如何将自定义属性添加到rails link_to的HTML输出中

Har*_*ood 16 ruby-on-rails jquery-mobile

使用rails版本2.3.8我试图获得HTML输出,如:

    <a href="/product/list" data-role="button">Product list</a>
Run Code Online (Sandbox Code Playgroud)

所以A标签具有自定义属性"data-role".(我想要"数据角色"属性的原因是我正在使用JQuery Mobile,它接受了这个属性并且做了它的魔力)所以我试图这样做

    <%= link_to "product list", :controller => "product", :action => "list", "data-role" => "button" %>
Run Code Online (Sandbox Code Playgroud)

根据本教程判断,可能适用于rails 3,但在rails 2.3.8中,它通过在链接URL上生成data-role = button参数来解释它.

我可以获得所需HTML输出的一种方法是使用url_for代替:

    <a href="<%=url_for :controller =>"product", :action => "list" %>" data-role="button">Product list</a> 
Run Code Online (Sandbox Code Playgroud)

有点长而丑陋.有没有办法让link_to在A标签中输出自定义属性(?)

Dog*_*ert 25

尝试

<%= link_to "product list", { :controller => "product", :action => "list" }, "data-role" => "button" %>
Run Code Online (Sandbox Code Playgroud)