Search code examples
ruby-on-railsrubystringmiddleman

Merge string and variable as argument?


I want to pass the string 'header__button' and the response from method classify(f) as the argument class to link_to.

I tried

<%= link_to f, '/dashboard', class: 'header__button' classify(f) %>

but Ruby won't allow it. How can it be done?


Solution

  • You can simply pass an array:

    <%= link_to f, '/dashboard', class: ['header__button', classify(f)] %>
    

    The documentation for tag and content_tag contains an example showing this usage (link_to calls content_tag to construct the <a> tag).