1

I currently have this code:

link_to 'add a new baz!', new_foo_bar_baz_path(@foo, @bar, baz: { thing: 'the-value' })

which generates this url:

http://ganxy.local/foos/1/bars/2/bazes/new?baz%5Bthing%5D=the-value

Because of some changes I'm making to my app I want to make the url generation polymorphic. So, something like this:

link_to 'add a new baz!', [@foo, @bar, :baz]# : { thing: 'the-value' })

Is there a way to add the ?baz%5Bthing%5D=the-value to the end, or do I need to generate the string manually?

John Bachir
  • 22,495
  • 29
  • 154
  • 227

3 Answers3

2

I wouldn't recommend to use polymorphic url because it 2x slower than helper method. Check out my post about this

ka8725
  • 2,788
  • 1
  • 24
  • 39
1

See Rails 3 - Nested resources and polymorphic paths: OK to two levels, but break at three

So you can write

link_to 'add a new baz!', polymorphic_url([@foo, @bar, :baz], thing: 'the-value')
Community
  • 1
  • 1
Dmitry Lihachev
  • 504
  • 6
  • 20
1

You can do this:

link_to 'add a new baz!', [[@foo, @bar, :baz], thing: 'the-value']
Mark Swardstrom
  • 17,217
  • 6
  • 62
  • 70