[英]rails polymorphic url params
I like polymorphic style url very much, so I can write 我非常喜欢多态风格的url,所以我可以写
link_to 'New taste', [:new, :taste]
instead of 代替
link_to 'New taste', new_taste_path
But is it possible to add query parameters to first one without using polymorphic_url
/ polymorphic_path
? 但是可以在不使用
polymorphic_url
/ polymorphic_path
情况下将查询参数添加到第一个参数吗?
No. When you pass an Array to these methods ( link_to
, redirect_to
, etc) the url argument is passed directly to url_for
, which itself calls polymorphic_path
with a single argument. 当您将Array传递给这些方法(
link_to
, redirect_to
等)时,url参数将直接传递给url_for
, url_for
本身使用单个参数调用polymorphic_path
。 As you stated polymorphic_path
allows params to be passed as the second argument, but they cannot be passed as in the first argument. 正如你所说的,
polymorphic_path
允许params作为第二个参数传递,但它们不能像第一个参数那样传递。
In order to pass params and use polymorphic routing you have to use polymorphic_path
/ polymorphic_url
like so: 为了传递params并使用多态路由,你必须使用
polymorphic_path
/ polymorphic_url
如下所示:
link_to 'New taste', polymorphic_path([:new, :taste], :spiciness => :on_fire)
是的 - 您可以这样传递:
link_to 'New taste', [[:new, :taste], :a_param => 'param']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.