Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hyphen in link_to property?

In my Rails app, I need to set a value for a custom data-* attribute on an anchor tag. However, hashes can't have hyphens if I'm not mistaken. I essentially want to do this:

<%= link_to 'Example', example_path, :class => 'something', :data-id => '15' %>

:data-id is not valid, however. What can I do to work around this?

like image 281
Matt Huggins Avatar asked Dec 05 '22 02:12

Matt Huggins


1 Answers

IIRC, for such purposes hashes and strings are equivalent, so you can use "data-id" instead of :data-id. Never checked for this particular method, though, so no guarantees.

like image 63
Nikita Rybak Avatar answered Dec 20 '22 02:12

Nikita Rybak