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 and recently updated to pass tests on Ruby 2.6.0 and Rails 5 Test coverage not complete.
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.
Development¶ ↑
Install with ‘bundle install` and run test with `bundle exec rspec`
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.