Reputation: 129
I'm building a site wide subnav, see code below:
= link_to "#{params[:controller].capitalize}", {:controller => "#{params[:controller]}", :action => "index"}
- if params[:action] != 'index'
>
= link_to "#{params[:action].capitalize.humanize}", {:controller => "#{params[:controller]}", :action => "#{params[:action]}"}
>
= "@#{params[:controller]}"
The last line renders:
@products
as a string which I'd like to render as a variable.
Upvotes: 1
Views: 268
Reputation: 51151
If you want to render the value of instance variable named '@' + params[:controller]
, you can use Object#instance_variable_get
method:
= instance_variable_get("@#{params[:controller]}")
Upvotes: 2