link_to对象数组,但具有新路径 [英] link_to array of objects but with new path

查看:82
本文介绍了link_to对象数组,但具有新路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由一系列对象生成的链接...

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' %>

但是这只会生成'/ businesses / 12 / posts /'而我想拥有一个' / new,因此为 / businesses / 12 / posts / new。使用link_to对象数组可能吗?在上述情况下,:action =>'new'似乎无能为力。

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.

@object可以是各种类型的对象,因此我不能使用new_business_post_path()。并且这些对象中的每个对象都有一条资源丰富的发帖路线

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

推荐答案

答案是使用:

[:new, @object, :post]

翻译为:

new_businesses_post()

这篇关于link_to对象数组,但具有新路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆