如何在link_to中包含title和class属性?

时间:2013-05-09 10:00:51

标签: html ruby-on-rails ruby ruby-on-rails-3

我正在尝试这个:

<%= link_to 'Test', '#', {title: "this is my images tooltop message", class: "tooltip"} %>

返回以下HTML:

<a href="#" class="tooltip">Test</a>

当我删除class属性时,我会得到:

<a href="#" title="this is my images tooltop message">Test</a>

如何在锚标记中设置titleclass,以便获得以下内容?

<a href="#" title="this is my images tooltop message" class="tooltip">Test</a>

4 个答案:

答案 0 :(得分:3)

你也可以这样做:

<%= link_to 'Test', '#', :class => "tooltip", :title => 'this is my images tooltop message' %>

它只是您喜欢的哈希表示法。

答案 1 :(得分:2)

我没用!我正在做的事实上是正确的。

我正在使用的工具提示jQuery插件删除了title属性 - http://calebjacob.com/tooltipster/

答案 2 :(得分:1)

<%= link_to 'Show', '#', { :title => "this is my images tooltop message", :class => "tooltip"} %>

旧的哈希表示法呈现出完美的HTML。我不知道为什么新的哈希语法会导致这种奇怪的行为。

答案 3 :(得分:0)

<%= link_to 'Test', '#', title: "this is my images tooltop message", class: "tooltip" %>