I have a rails 4.2 app. I would like to have the whole tr
to be clickable and take the user to the user to the product show page.
At the moment the html gets rendered without <href..
and I don't exactly understand why. What did I miss?
index.html.erb
<div class="panel panel-default">
<table class="table">
<tbody class="product-profile-index">
<%= render @products %>
</tbody>
</table>
</div>
_product.html.erb (partial for index page)
<%= 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;
}
}
}
UPDATE:
If I wrap just a smaller part of html like this, then it's working:
<%=link_to product %>
<%= product.name%>
<% end %>
尝试使用此代码
<tr class = "product-index-row" data-href"/product/<%=@product.id%>">
I found a solution. It's not DRY but working pretty well.
I had to pass the link into each td
like this:
.......
<td>
<%= link_to(product, html_options = {style:"display:block;"}) do %>
......
<% end %>
</td>
..........
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.