https://github.com/yhirano55/table_help
Provide helper methods to build collection or resource tables for Rails 5
https://github.com/yhirano55/table_help
actionview erb rails5
Last synced: 8 months ago
JSON representation
Provide helper methods to build collection or resource tables for Rails 5
- Host: GitHub
- URL: https://github.com/yhirano55/table_help
- Owner: yhirano55
- License: mit
- Created: 2017-10-07T23:39:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-15T09:17:01.000Z (about 8 years ago)
- Last Synced: 2025-01-20T01:14:52.040Z (over 1 year ago)
- Topics: actionview, erb, rails5
- Language: Ruby
- Size: 30.3 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# TableHelp
[](https://opensource.org/licenses/MIT)
[](https://badge.fury.io/rb/table_help)
[](https://travis-ci.org/yhirano55/table_help)
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](https://github.com/activeadmin/activeadmin).
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'table_help'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install table_help
## Usage
### Collection
```html+erb
<%= 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| %>
- <%= link_to "Show", article %>
- <%= link_to "Edit", edit_article_path(article) %>
- <%= link_to "Destroy", article, method: :delete %>
<% end %>
<% end %>
```
### Resource
```html+erb
<%= 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| %>
- <%= link_to "Edit", edit_article_path(article) %>
- <%= link_to "Destroy", article, method: :delete %>
<% end %>
<% end %>
```
## Configuration
You can change the default options for each table.
```ruby
# 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](http://opensource.org/licenses/MIT).