动态生成一个`link_to`到控制器动作`edit`

我正在使用Ruby on Rails 3.0.7,我想动态生成一个link_to到控制器动作edit 。 我必须在部分模板中使用它,但问题是我为不同的模型数据渲染相同的部分模板(也就是说,我传递不同类实例的局部变量)。

所以我不能使用路线“神奇的RoR方式”

 `edit__path()`. 

我想做类似以下的事情:

 link_to( @resource_class_instance, :action => 'edit') # This example is wrong, but it suggests the idea 

可能吗? 如果是这样,我该怎么办?

您可以使用“数组样式”编写路由,如下所示:

 = link_to "Edit", [:edit, @your_resource] 

有一个edit_polymorphic_url和( edit_polymorphic_path )助手可用: https : //github.com/rails/…/polymorphic_routes.rb#L32