8fa97b9513b66cccc2db021782863b3b

I need to make tables to list user, groups,... in my rails app. Below is such a table for groups (simplified).

The main difference between them is the table body. Is it possible to make a helper method to do this DRY?

Thanks in advance

<table>
  <thead> <th colspan="2">Groups</th></thead>
  
  <tbody>
    <% for group in @groups %>
      <tr>
        <td><%= image_tag group.picture %></td>
        <td>
          <h6><%=link_to h(group.name), group %></h6>
          <%= h group.description %>
        </td>
      </tr>
    <% end %>
  </tbody>
  
  <tfoot><tr><td><%= will_paginate @groups%></td></tr></tfoot>
</table>

Refactorings

No refactoring yet !

3399cbfb9e5fec93c324789b29309911

nakajima

October 18, 2008, October 18, 2008 22:40, permalink

No rating. Login to rate!

You can use a partial to clean this up a bit, though it doesn't seem totally bad as is.

<table>
  <thead> <th colspan="2">Groups</th></thead>
  <tbody>
    <%= render :partial => "group", :collection => @groups %>
  </tbody>
  <tfoot><tr><td><%= will_paginate @groups %></td></tr></tfoot>
</table>
<tr>
  <td><%= image_tag group.picture %></td>
  <td>
    <h6><%=link_to h(group.name), group %></h6>
    <%= h group.description %>
  </td>
</tr>

Your refactoring





Format Copy from initial code

or Cancel