【发布时间】:2016-02-19 12:37:25
【问题描述】:
我有一个 rails 4.2 应用程序。我想让整个tr 可以点击并将用户带到用户到产品展示页面。
目前,html 在没有 <href.. 的情况下呈现,我不完全明白为什么。我错过了什么?
index.html.erb
<div class="panel panel-default">
<table class="table">
<tbody class="product-profile-index">
<%= render @products %>
</tbody>
</table>
</div>
_product.html.erb(部分用于索引页)
<%= link_to product do %>
<tr class = "product-index-row">
<td class="col-md-3 name">
<span class="product-image">
<%= image_tag attachment_url(product, :product_image, :fill, 45, 45) %>
</span>
<span class="product-name">
<%= product.name %>
</span>
</td>
<td class="col-md-6 oneliner">
<%= product.oneliner %>
</td>
<td class="col-md-3 updated">
<%= local_time_ago(product.updated_at) %>
</td>
</tr>
<% end %>
css.scss
.product-profile-index {
.product-index-row {
&:hover {
background-color: $gray-medium-light;
}
}
}
更新:
如果我像这样只包装 html 的一小部分,那么它就可以工作了:
<%=link_to product %>
<%= product.name%>
<% end %>
【问题讨论】:
-
您能在页面某处添加
<%= product_path(@product) %>并告诉我们它输出的内容吗? -
它工作正常。我曾经用
<%=link_to product %><%= product.name%><% end %>使用它并且工作正常。 (我只是将实例变量放在我的问题中以使其更易于阅读,但这不是问题) -
优秀。你可以添加它以便我们看到吗?
标签: html css ruby-on-rails erb link-to