Search code examples
ruby-on-railsclassruby-on-rails-5link-tocustom-data-attribute

How do I create a link_to tag with both class and data fields?


I want to create a Rails link_to tag that will ultimately spawn a dialog box and so it just link to "#". However, I would like it to have a class and data attribute. But when I try this

<%= link_to "What's This?", "#", {class: "more_info"}, :data => { :more_info => 'mt_hashes_info' } %>

I get the error

wrong number of arguments (given 4, expected 0..3)

What's the right way to construct this link?


Solution

  • This is what it should look like:

    <%= link_to "What's This?", "#", {:class => "more_info", :data => { :more_info => 'mt_hashes_info' }} %>

    Class and Data both go into the same options hash.