Search code examples
rubylink-to

How to interpolate ruby language in a link to path


I would like to insert the type of my object in my link to. this one is not always the same so I don't want to write it in real letter. I would like to write something like :

link to "my mission", edit_+ mission.type.downcase + _path(mission)

I don't even know if its possible. Thanks for your help


Solution

  • You can use instance_eval like:

    link_to "my mission", instance_eval("edit_#{mission.type.downcase}_path(mission)")