简体   繁体   中英

rails polymorphic url params

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)

是的 - 您可以这样传递:

link_to 'New taste', [[:new, :taste], :a_param => 'param']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM