2013-07-19 51 views
0

我有需要循環的搜索結果。每個循環都應該給我兩個表格行。到目前爲止的代碼是:Content_tag_for rails 3.2中的故障

<tbody> 
    <%= content_tag_for(:tr, @results) do |material| %> 
    <tr> 
     <td>Some content</td> 
     <td>Some content</td> 
     <td>Some content</td> 
    </tr> 
    <tr class="hide"> 
     <td>Some content</td> 
     <td>Some content</td> 
     <td>Some content</td> 
    </tr> 
    <% end %> 
</tbody> 

的問題是,我用class和id在一個單獨的連續兩行以上獲得。我需要將這兩行包裹在一個ID中。

例如

<tr class="X" id="X"></tr> 
<tr> 
    <td>Some content</td> 
    <td>Some content</td> 
    <td>Some content</td> 
</tr> 
<tr class="hide"> 
    <td>Some content</td> 
    <td>Some content</td> 
    <td>Some content</td> 
</tr> 

我也有同樣的問題,當我嘗試使用div_for。在那種情況下,我得到了所有在行之前堆疊的ID。

我在做什麼錯?

回答

0

問題是你不能用另外一種方法來包裝。解決的辦法是寫出以下內容:

<tbody> 
    <%= content_tag_for(:tr, @results) do |material| %> 
    <td>Some content</td> 
    <td>Some content</td> 
    <td>Some content</td> 

    <tr class="hide"> 
     <td>Some content</td> 
     <td>Some content</td> 
     <td>Some content</td> 
    </tr> 
<% end %> 
</tbody> 

前三位的是用一個id包裹,而另一個只是逐字轉載。