Orsay Orsay - 1 year ago 64
Ruby Question

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

Answer Source

You can use instance_eval like:

link_to "my mission", instance_eval("edit_#{mission.type.downcase}_path(mission)")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download