Hi,
how can I remember some state within a partial renderer?
Problem at hand: my partial _testitem.html.erb
renders table rows of a collection of testitems. A Testitem
has an id
and a sortkey
and the partial is called with
<%= render :partial => "testitem", :collection => @testbox.testitems.sort_by{|x| [x.sortkey, x.id]} %>
i.e. all testitems are sorted by the sortkey and then by their id. Now I'd like to display a table column that shows the current sortkey and I thought it would be neat to use
<td rowspan="<%= Testitem.count_by_sql "SELECT count(*) from testitems where sortkey=#{testitem.sortkey}" %>"><%=h testitem.sortkey %></td>
which of course breaks the table, as every <td>
get's the rowspan. The expected result would look somewhat like
Group | Id | Description |
----------------------------------
1 | 1 | ... |
--------------------------
| 2 | ... |
--------------------------
| 16 | ... |
----------------------------------
2 | 3 | ... |
----------------------------------
3 | 4 | ... |
| 10 | ... |
| 11 | ... |
---------------------------------
Is there a way to "remember" (within _testitem.html.erb
) the fact that I added the <td rowspan="">
already for a given sortkey
?
Thanks for helping me out.