开发者

Using hyphen in link_to property?

开发者 https://www.devze.com 2023-01-06 11:13 出处:网络
In my Rails app, I need to set a value for a custom data-* attribute on an anchor tag.However, hashes can\'t hav开发者_如何学Pythone hyphens if I\'m not mistaken.I essentially want to do this:

In my Rails app, I need to set a value for a custom data-* attribute on an anchor tag. However, hashes can't hav开发者_如何学Pythone 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?


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.


I think in Rails 3 you can do

link_to "Click Here", root_path, :data => { :id => @model.id }

for all data attributes.

0

精彩评论

暂无评论...
验证码 换一张
取 消