Html 将类添加到Rails中的content_标记

Html 将类添加到Rails中的content_标记,html,css,ruby-on-rails,Html,Css,Ruby On Rails,我想在Rails代码中的(:I)标记中添加一个类: <td><%= link_to content_tag(:i), item %></td> 我希望最终代码如下所示: <td><a href="/items/2"><i class="#"></i></a></td> 试试这个 “#”),item%>@Dogbert是正确的,只是您需要传递nil作为第二个参数,因为content

我想在Rails代码中的
(:I)
标记中添加一个类:

<td><%= link_to content_tag(:i), item %></td>

我希望最终代码如下所示:

<td><a href="/items/2"><i class="#"></i></a></td>

试试这个


“#”),item%>

@Dogbert是正确的,只是您需要传递
nil
作为第二个参数,因为
content\u标记
定义为

def content_tag(tag, content_or_options_with_block=nil, options=nil, escape=true, &block)
  ...
end
第二个参数仅在传递块时才被视为内容。为了扩展它,在该点上传入的任何额外选项都将成为HTML属性,因此相同的表单适用于诸如ID、data-*等内容

content_tag(:i, nil, class: '#', id: 'foo', data: {foo: 'bar'})
将成为

<i class="#" id="foo" data-foo="bar"></i>