开发者

link_to array of objects but with new path

开发者 https://www.devze.com 2023-04-02 01:15 出处:网络
I hav开发者_如何学JAVAe 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

I hav开发者_如何学JAVAe 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


The answer is to use:

[:new, @object, :post]

Which translates to:

new_businesses_post()
0

精彩评论

暂无评论...
验证码 换一张
取 消