1

我正在尝试使 link_to 函数附加一个 css 类,

我的代码是这样的:

<%= link_to newGame do%>
<%= image_tag newGame.image_url.to_s %>
<% end %>

它将图像链接到其内容,但我需要在链接中添加一个 class="thumbnail",

IE:

<a href="/games/:id" class="thumbnaill>

而不是它当前产生的:

<a href="/games/:id">

谢谢

4

2 回答 2

1

参考链接到

<%= link_to newGame, class: 'thumbnail'  do %>

使用较旧的参数样式时要小心,因为需要额外的文字哈希:

<%= link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article" %>
#Gives <a href="/articles" class="article" id="news">Articles</a>
于 2012-09-25T09:30:24.173 回答
0

你可以做

<%= link_to newGame, class: 'thumbnail' do %>
  <%= image_tag newGame.image_url.to_s %>
<% end %>
于 2012-09-25T09:21:08.067 回答