Search code examples
ruby-on-railsclassruby-on-rails-4link-to

Can't add class to Rails link_to


I tried to add a simple HTML class to my link_to tag:

<%= link_to "Individual Images", action: 'feature_highlights', site_title: site.title, class: "btn" %>

..but it gets appended to the URL instead:

How do I add a class to my link_to tag?


Solution

  • As per the API docs:

    Be careful when using the older argument style, as an extra literal hash is needed

    So, the solution was

    <%= link_to "Individual Images", { action: 'feature_highlights', site_title: site.title }, class: "btn" %>