TableFor

Renders a table for your model collection. Like show_for, but for collections...

Disclaimer

Should not be considered stable. Briefly tested under rails 3 running ruby 1.8.7 and 1.9.2 Test coverage not yet up to speed.

Installation

Add the below line to your gem file and run bundle install gem 'table_for'

Basic Usage

In your erb views:

<%= table_for Product, @products do |table| %>
<%= table.head :name, :size, :description, :price %>
<%= table.body do |row| %>
  <%= row.cell :name %>
  <%= row.cells :size, :description %>
  <%= row.cell number_to_currency(row.record.price) %>
<% end %>
<%= table.foot do %>
  <%= link_to "Add product", new_product_path %>
<% end %>
<% end %>

Or:

<%= table_for Product, @products do |table| %>
<%= table.columns :name, :size, :description, :price %>
<%= table.foot do %>
  <%= link_to "Add product", new_product_path %>
<% end %>
<% end %>

The footer and rows can be filtered out through the TableFor.footer_filter/row_filter methods.

Credits and contributors

  • Jonas Nicklas (jnicklas) who actually wrote most of the code while we pair-programmed.
  • Elabs for sponsoring with development time.
  • The authors of the show_for gem for providing the inspiration.