2016-02-19 75 views
1

我有一個rails 4.2應用程序。我希望整個tr都是可點擊的,並將用戶帶到用戶的產品展示頁面。rails links_to幫手html塊

目前的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; 
    } 
    } 
} 

UPDATE:

如果我只包裹ht的一小部分毫升這樣的,那麼它的工作:

<%=link_to product %> 
    <%= product.name%> 
<% end %> 
+0

你可以添加'<%= product_path(@product)%>'某處在頁面上,讓我們知道什麼是輸出? – jeffdill2

+0

它工作。我曾經用'<%= link_to product%><%= product.name%><% end %>'來使用它,並且運行良好。 (我只是把實例變量放在我的問題中,以便於閱讀,但這不是問題) –

+0

非常好。你可以添加它,所以我們可以看到它嗎? – jeffdill2

回答

0

嘗試使用此代碼

<tr class = "product-index-row" data-href"/product/<%[email protected]%>"> 
+0

不適用於:( –

0

我找到了解決辦法。它不幹,但工作得很好。

我不得不鏈接進入各td這樣的:

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