问题
Query:
I have a link like
<%= link_to "link_name", :controller => "some_controller", :action =>
"some_action", :id => "some_id", :first_param => {:second_param => "some
value"} %>
and in my routes.rb
map.connect '/some_name/:id' :controller => "some_controller", :action
=> "some_action"
Above code is giving me a URL like
http://localhost:3000/some_name/some_id
my requirement is to construct the URL as:
http://localhost:3000/some_name/some_id/value_inside_params[:first_param][:second_param]
Please help me out.
Thanks,
Saurabh
回答1:
You can use route globbing:
map.connect '/some_name/:id/*other', :controller => 'some_controller',
:action => 'some_action'
—this will make the additional parameters accessible within your action via params[:other]
.
来源:https://stackoverflow.com/questions/3323678/how-to-accept-hash-parameters-in-routes