I like polymorphic style url very much, so I can write
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
?
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. As you stated polymorphic_path
allows params to be passed as the second argument, but they cannot be passed as in the first argument.
In order to pass params and use polymorphic routing you have to use polymorphic_path
/ polymorphic_url
like so:
link_to 'New taste', polymorphic_path([:new, :taste], :spiciness => :on_fire)
Yes - you can pass it like so:
link_to 'New taste', [[:new, :taste], :a_param => 'param']
I think it is more this syntax on Rails >= 4.2:
link_to 'New taste', [:new, :taste, { a_param: 'param' }]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With