Routing with Parameters in Ruby on Rails -
i'm new rails, , i'm struggling handling routing correctly. right have link called "details," , when user clicks on method "view_details" (within pages controller) called location parameter i'm passing in:
<%= link_to "details", :controller => "pages", :action => "view_details", :location => v["coordinates"]%> in routes.rb file, have:
get 'pages/view_details/:location', to: 'pages#view_details' i getting following error: no route matches [get] "/pages/view_details/latitude=37.3505570824247&longitude=-121.922104884669"
when rake routes, see (with no prefix): 
how can fix this?
the problem passing hash value location parameter so, instead of adding 1 parameter (i.e. location), adds 2 parameters (i.e. latitud , longitude) , routing fails.
to fix set route without location, this:
get 'pages/view_details', to: 'pages#view_details' now, using same link have now, receive latitud , longitude parameters grouped in location query string, similar to:
pages/view_details?location%5blatitude%5d=37.3505570824247&location%5blongitude%5d=121.922104884669 and can use them in controller params (as other parameter), example:
latitude = params[:location][:latitude] longitud = params[:location][:longitude]
Comments
Post a Comment