Rails中带连字符的html标记属性的语法

时间:2014-07-13 17:40:07

标签: ruby-on-rails ruby-on-rails-4

在rails标签中,带连字符的属性的语法是什么?例如,data-something: "1234"是无效的语法。

<%= link_to "foo", "/bar", class: "myClass", id: "myID", data-something: "1234" %>

2 个答案:

答案 0 :(得分:2)

已经有答案,但一般来说使用“带连字符的属性”(不确定这是否是科学术语),只是将它包装成这样......

<%= link_to "foo", "/bar", "data-something" => "1234" %>

答案 1 :(得分:1)

尝试:

<%= link_to "foo", "/bar", class: "myClass", id: "myID", data: { something: "1234"} %>