Is it possible to "build" a path in an erb file like this? The path's name should be dependent on the object's class name. The path being build already exists in the routes.rb file. I just want to dynamically choose a part of the path being generated so I don't have to use a conditional and repetitive code.
<% custom_path = "hide_#{object.class}_path" %>
<%= link_to 'Do something', custom_path(object) %>
The above example doesn't work because I don't know how to "use" the new path correctly. I guess I have to "call" the route by some "meta" way? Like object.call(method)
in Ruby. But I don't know how to do this in Rails.
An example to clarify: let's say the object's class is Car, then the path in the variable should be: hide_car_path
.
The error for the example above looks like this:
undefined method `custom_path' for #<#<Class:0x00000108afac40>:0x000001091fd3a8>