Bac*_*cko 6 ruby ruby-on-rails dynamic link-to ruby-on-rails-3
我on Rails的3.0.7使用Ruby,我想生成一个link_to控制器动作edit,动态.我必须在部分模板中使用它,但问题是我为不同的模型数据渲染相同的部分模板(也就是说,我传递不同类实例的局部变量).
所以我不能使用路线"神奇的RoR方式"
`edit_<singular_name_of_the_resource>_path(<resource_class_instance>)`.
Run Code Online (Sandbox Code Playgroud)
我想做类似以下的事情:
link_to( @resource_class_instance, :action => 'edit') # This example is wrong, but it suggests the idea
Run Code Online (Sandbox Code Playgroud)
可能吗?如果是这样,我该怎么做?
Nic*_*nco 10
您可以使用"数组样式"编写路由,如下所示:
= link_to "Edit", [:edit, @your_resource]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6683 次 |
| 最近记录: |