-1

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

Haseeb Ahmad
  • 7,914
  • 12
  • 55
  • 133

1 Answers1

1

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

Miron Marczuk
  • 81
  • 1
  • 7