Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using link_to to add url params when not using a path helper method

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...].

like image 464
Andrew Lank Avatar asked Jan 17 '23 16:01

Andrew Lank


1 Answers

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.

like image 195
Salil Avatar answered Apr 08 '23 22:04

Salil