Create the `link_to` controller action` edit`, dynamically

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

Therefore, I cannot use the RoR magic path route

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

I would like to do 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 this?

+6
source share
2 answers

You can write routes using the "array style" as follows:

 = link_to "Edit", [:edit, @your_resource] 
+10
source

There is an accessible help for edit_polymorphic_url and ( edit_polymorphic_path ): https://github.com/rails/.../polymorphic_routes.rb#L32

+1
source

Source: https://habr.com/ru/post/892826/


All Articles