带有 URL 参数的 Rails link_to 操作 [英] Rails link_to action with URL parameters
本文介绍了带有 URL 参数的 Rails link_to 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这样的路线
get 'controller/:id/action/:param' => 'Controller#action'
How can I use link_to
to create a link like <a href="/controller/12345/action/abcde">
?
到目前为止我已经得到了 link_to 'Link text', {:action =>'动作'}
So far I have gotten link_to 'Link text', {:action => 'action'}
但使用 link_to 'Link text', {:action =>'动作', :param =>'abcde'}
推荐答案
您可以命名您的路线:
get 'controller/:id/action/:param' => 'Controller#action', :as => 'custom_show'
这应该会给你一个新的 url helper,你可以像这样使用:
This should give you a new url helper which you can use like this:
<%= link_to "Foobar", custom_show_path(:id=>1234, :param=>'my_param') %>
这篇关于带有 URL 参数的 Rails link_to 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文