繁体   English   中英

带有HTML块的rails links_to helper

[英]rails links_to helper with html block

我有一个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 %>

尝试使用此代码

<tr class = "product-index-row" data-href"/product/<%=@product.id%>"> 

我找到了解决方案。 它不是干的,但是运行得很好。

我必须像这样将链接传递到每个td

.......
<td>
<%= link_to(product, html_options = {style:"display:block;"}) do %>
......
<% end %>
</td>
..........

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM