开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜