I am trying to create a helper function (e.g. in application_helper.rb ) that generates link_to based on the parameters passed to the helper function. If I put the link in an ERB file, this would be in the format:
<%= link_to 'Some Text', { :controller => 'a_controller', :action => 'an_action' } %>
In a helper function, text, controller, and action are transmitted or evaluated. Code in helper function:
params = "{ :controller => '#{controller}', :action => '#{action_to_take}'}" html = "#{link_to some_text, params }<p />" return html
The generated link has the correct text, however the parameters are literally the contents of the params string.
How can I get the params string to evaluate (as in the ERB file)?
source share