开发者

Generate a `link_to` to the controller action `edit`, dynamically

开发者 https://www.devze.com 2023-03-21 00:13 出处:网络
I am using Ruby on Rails 3.0.7 and I would like to generate a link_to to the controller action edit, dynamically. I have to use it in a partial template but the issue is that I am rendering that same

I am using Ruby on Rails 3.0.7 and I would like to generate a link_to to the controller action edit, dynamically. I have to use it in a partial template but the issue is that I am rendering that same partial template for different model data (that is, I pass local variables of different class instances in that).

So I can not use the route "magical RoR way"

`edit_<singular_name_of_the_resource>_path(<resource_class_instance>)`.

I would like to make something like the following:

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

Is it possible? If so, how can I do 开发者_运维知识库that?


You can write routes using the "array style" like this :

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


There is a edit_polymorphic_url and (edit_polymorphic_path) helper available: https://github.com/rails/.../polymorphic_routes.rb#L32

0

精彩评论

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