link_to array of objects but with new path

僤鯓⒐⒋嵵緔 提交于 2019-12-21 05:35:24

问题


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:


The answer is to use:

[:new, @object, :post]

Which translates to:

new_businesses_post()


来源:https://stackoverflow.com/questions/7258531/link-to-array-of-objects-but-with-new-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!