I'm new to rails, and I'm struggling with handling the routing correctly.
Right now I have a link called "details," and when the user clicks on it I would like the method "view_details" (within the pages controller) to be called with a location parameter that I'm passing in:
<%= link_to "Details", :controller => "pages", :action => "view_details",
:location => v["coordinates"]%>
get 'pages/view_details/:location', to: 'pages#view_details'
The problem is that you are passing a hash as a value for
location parameter so, instead of just adding one parameter (i.e.
location), it adds two parameters (i.e.
longitude) and your routing fails.
To fix this you could set your route without
location, like this:
get 'pages/view_details', to: 'pages#view_details'
Now, using the same link you have now, you will receive
longitude parameters grouped in
location as a query string, something similar to:
And you can use them in your controller with
params (as with any other parameter), for example:
latitude = params[:location][:latitude] longitud = params[:location][:longitude]