Rails - Is there a shortcut to pass all existing params?

人盡茶涼 提交于 2020-01-01 06:58:12

问题


How can you pass all parameters to a controller action?

# instead of:
<%= link_to mylist_url(id: params[:id], se: "true", st: params[:st], re: params[:re], li: params[:li]) do %> ... <% end %>

# something like:
<% link_to mylist_url(params: :all, se: "true") do %> ... <% end %>

回答1:


Can you just use Hash#merge?, something like:

<% link_to mylist_url(params.merge(:se=>"true")) do %> ... <% end %>


来源:https://stackoverflow.com/questions/4112425/rails-is-there-a-shortcut-to-pass-all-existing-params

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