Wrapp your model collection in a table, simular to show_for but for collections
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.bundle
lib
spec
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
init.rb
table_for.gemspec

README.rdoc

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.