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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -