link_to array of objects but with new path

2020-06-25 04:21发布

I have a link that is generated from an array of objects...

<%= link_to 'Add a Post', [@object, Post.new], :action => 'new', :remote => true, :class => 'button gray medium' %>

however this only generates '/businesses/12/posts/' while I would like to have a '/new' at the end of it, therefore '/businesses/12/posts/new'. Is this possible with link_to array of objects? The :action => 'new' appears to do nothing in the case above.

The @object could be various types of objects so I can't use the new_business_post_path(). And each of these objects will have a resourceful route to posts

1条回答
可以哭但决不认输i
2楼-- · 2020-06-25 04:42

The answer is to use:

[:new, @object, :post]

Which translates to:

new_businesses_post()
查看更多
登录 后发表回答