Project

table_help

0.0
No commit activity in last 3 years
No release in over 3 years
Provide helper methods to build collection or resource tables for Rails 5
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15

Runtime

>= 5.0
 Project Readme

TableHelp

License: MIT Gem Version Build Status

Provide helper methods to build collection or resource tables for Rails 5.

table_for and attributes_table_for helper methods implemented in TableHelp are inspired by ActiveAdmin.

Installation

Add this line to your application's Gemfile:

gem 'table_help'

And then execute:

$ bundle

Or install it yourself as:

$ gem install table_help

Usage

Collection

<%= table_for @articles do |t| %>
  <% t.column :title %>
  <% t.column :body do |article| %>
    <%= truncate(article.body) %>
  <% end %>
  <% t.column :created_at %>
  <% t.column :updated_at %>
  <% t.column do |article| %>
    <ul>
      <li><%= link_to "Show", article %></li>
      <li><%= link_to "Edit", edit_article_path(article) %></li>
      <li><%= link_to "Destroy", article, method: :delete %></li>
    </ul>
  <% end %>
<% end %>

Resource

<%= attributes_table_for @article do |t| %>
  <% t.row :title %>
  <% t.row :body do |article| %>
    <%= truncate(article.body) %>
  <% end %>
  <% t.row :created_at %>
  <% t.row :updated_at %>
  <% t.row do |article| %>
    <ul>
      <li><%= link_to "Edit", edit_article_path(article) %></li>
      <li><%= link_to "Destroy", article, method: :delete %></li>
    </ul>
  <% end %>
<% end %>

Configuration

You can change the default options for each table.

# config/initializers/table_help.rb
TableHelp.config.default_options = {
  table_for: { class: "table_for your_optional_style", border: "1" },
  attributes_table_for: { class: "attributes_table_for your_optional_style", border: "0" },
}

License

The gem is available as open source under the terms of the MIT License.