SimpleTableFor
A simple helper to generate tables in Rails applications.
In your Gemfile:
gem 'simple_table_for'
Parameters:
table_for(collection, headers, , &block)
Usage:
<%= table_for @posts, %w[Title Text Date Comments\ count -] do |post| %>
<%= field post.title %>
<%= field post.text %>
<%= field post.date %>
<%= field post.comments.count %>
<%= field link_to('View', post) %>
<% end %>
You can optionally add an id or classes to tables and fields:
<%= table_for @posts, %w[Title -], id: 'posts-table', class: 'table' do |post| %>
<%= field post.title, class: 'post-title' %>
<%= field link_to('View', post), class: 'view' %>
<% end %>
You can also set default id and class for tables:
# application.rb
class Application < Rails:Application
config.simple_table_for.defaults = {
class: 'table table-condensed table-striped table-bordered'
}
end
This project uses MIT-LICENSE.
Contributing
- Fork it ( https://github.com/andreynering/simple_table_for/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request