Mat*_*ins 4 anchor hash html5 ruby-on-rails
在我的Rails应用程序中,我需要为锚标记上的自定义data-*属性设置一个值.但是,如果我没有弄错,哈希不能有连字符.我基本上想要这样做:
<%= link_to 'Example', example_path, :class => 'something', :data-id => '15' %>
Run Code Online (Sandbox Code Playgroud)
:data-id但是,无效.我该怎么做才能解决这个问题?
IIRC,出于此目的,哈希和字符串是等效的,因此您可以使用"data-id"而不是:data-id.但是,从未检查过这种特殊方法,因此无法保证.