部分レンダラー内の状態をどのように記憶できますか?
当面の問題: 私のパーシャル_testitem.html.erb
は、testitem のコレクションのテーブル行をレンダリングします。ATestitem
には anid
と a がsortkey
あり、パーシャルは with で呼び出されます
<%= render :partial => "testitem", :collection => @testbox.testitems.sort_by{|x| [x.sortkey, x.id]} %>
つまり、すべてのテストアイテムはソートキーでソートされ、次に ID でソートされます。ここで、現在のソートキーを示すテーブル列を表示したいと思います。
<td rowspan="<%= Testitem.count_by_sql "SELECT count(*) from testitems where sortkey=#{testitem.sortkey}" %>"><%=h testitem.sortkey %></td>
もちろん、すべての取得が行スパンであるため、これはテーブルを壊します<td>
。期待される結果は、次のようになります。
Group | Id | Description |
----------------------------------
1 | 1 | ... |
--------------------------
| 2 | ... |
--------------------------
| 16 | ... |
----------------------------------
2 | 3 | ... |
----------------------------------
3 | 4 | ... |
| 10 | ... |
| 11 | ... |
---------------------------------
特定の に既に_testitem.html.erb
追加したという事実を(内で) 「覚える」方法はありますか?<td rowspan="">
sortkey
助けてくれてありがとう。