I'm using link_to to build my URL and I'm doing this kind of stuff
<%= link_to "new wire", [:new, @object, @post], :class => 'green', ...
But how would I add url params through link_to? For example I want the URL to be
http://www.something.com/groups/3/posts/4?a_param=23
without having to use the new_group_post_path(@group, @post, :a_param => '23') helper.
UPDATE:
Just to be more clear, I don't know what @object is, it could be a Group object, Member object etc, nor do I want to use a long and binding if/elsif/elsif...end condition to locate which object in turn to know what url helper (ie new_group_post_path() or new_member_post_path() ...) therefore the reason for having Rails guess the URL for me using the array struct shown above ie.[@object, @post...].
This should work:
<%= link_to "new wire", polymorphic_path([:new, @object, @post], a_param: '23', b_param: '24'), :class => 'green', ...
Refer polymorphic_path for details.
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