Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolation in Rails Route Helper

Is there any way of interpolating into a call to a route helper?

I have a partial in which I pass a resource (User, Gallery etc) as a local called resource. I need a link to edit the resource, but I need the link to be different for each resource:

For a user the link needs to use the helper edit_user_path, for Gallery it needs to use edit_gallery_path etc.

So I need a way to interpolate the resource name into the helper (Pseudo code): edit_{resource.name}_path

like image 826
Undistraction Avatar asked Jun 04 '13 15:06

Undistraction


1 Answers

You can replace edit_user_path with send("edit_user_path"). Already verified in console.

Now you can interpolate the string inside.

like image 86
Billy Chan Avatar answered Jan 03 '23 16:01

Billy Chan