我喜欢多态性风格的URL非常多,所以我可以写轨多态性网址参数
link_to 'New taste', [:new, :taste]
,而不是
link_to 'New taste', new_taste_path
但是,它可以添加查询参数到第一个不使用polymorphic_url
/polymorphic_path
?
我喜欢多态性风格的URL非常多,所以我可以写轨多态性网址参数
link_to 'New taste', [:new, :taste]
,而不是
link_to 'New taste', new_taste_path
但是,它可以添加查询参数到第一个不使用polymorphic_url
/polymorphic_path
?
是 - 你可以把它像这样:
link_to 'New taste', [[:new, :taste], :a_param => 'param']
似乎它仅在rails中可用〜> 4.1 – tig 2014-11-05 22:35:01
号当传递数组于这些方法(link_to
,redirect_to
等)url参数被直接传递到url_for
,它本身具有一个参数调用polymorphic_path
。正如您所说polymorphic_path
允许params作为第二个参数传递,但它们不能像第一个参数那样传递。
为了通过PARAMS和使用多态路由,你必须使用polymorphic_path
/polymorphic_url
像这样:
link_to 'New taste', polymorphic_path([:new, :taste], :spiciness => :on_fire)
据我所知你不能。 – vise 2010-09-28 21:24:38
你的意思是'link_to'New taste',[:new,:taste],:a_param =>'param''是不可能的? – Yannis 2010-09-28 21:33:05
@Yannis:不,这会将锚点标记的属性添加到 – tig 2010-09-28 22:28:39