Search code examples
ruby-on-railsrubylink-to

How to add data-webm-clickable in link_to rails


I want to add data-webm-clickable in link_to

I tried

link_to(link_hash[:title],link_hash[:path].to_s, data: { webm-clickvalue: link_hash[:class]})

link_to(link_hash[:title],link_hash[:path].to_s, data: { webm: {clickvalue: link_hash[:class]}})

But none of them works


Solution

  • To include dash inside a key in Hash, you can either: surround it by quotes or use underscore.

    Try this:

    <%= link_to @link_hash[:title], @link_hash[:path], data: { 'webm-clickvalue': @link_hash[:class] } %>
    

    or this:

    <%= link_to @link_hash[:title], @link_hash[:path], data: { webm_clickvalue': @link_hash[:class] } %>
    

    Note that qoutes this will work with ruby > 2.1, and undescore with Rails >= 4