How to accept hash parameters in routes

拥有回忆 提交于 2019-12-11 02:10:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!