philosophy: Creating simple and powerful generating table mechanism which allow create and manipulate a lot of tables in a seconds.
gem 'meta_table', :require => true
//= require meta_table
*= require meta_table
rails g mtw
rake db:migrate
# posts_controller
class PostsController < ApplicationController
meta_table :post,
[
{key: :id, label: 'Number'},
{key: :logo, label: 'Preview', render_text: "<%= image_tag(record.logo, style:'height: 100px;width:100px;') %>"},
{key: :title, searchable: true},
{key: :published, label: 'Shown?'},
{key: :content, render_text: "<%= record.content %>", searchable: true},
{key: :content_type, render_text: "record.content_type"},
:views_count,
:tag_list,
{key: :user, method: :email, label: "Created By Email"},
{key: :actions, label: 'Actions From Attrs', render_text: [:show, [:edit, :admin],[:destroy, :admin], "<%= link_to 'Edit', edit_admin_post_path(record), class: 'button small' %>"]}
],
{:scope => 'desc.articles', per_page_choises: [4, 12, 24], includes: [:categories]}
def index
@table = render_posts_table
end
and then in 'posts/index.html.erb'
<%= @table %>
actions detailed:
actions: [:show, [:destroy, :admin], "<%= link_to record.title, your_path(record) %>"]
# :show generates record show path
# [:edit, :namespace] generates record edit path with namespace
# "<%= your code here %>" anything which works inside your app
pass only symbols to get raw data
... [:email, :name, :your_method/column_name]
use hash syntax to specify more details
... :table_name, [{key: :id, label: 'Number', render_text: 'value.html_safe'}, {...}]
# key: is attrubute/method name
# label: change column name to record you added -> i18n will be soon
# searchable: makes column searchable in basic sql like search
# render_text: execute your code with each record. record is keyword that means record in database -> no rescue here yet
# render_text: when key is :actions you can pass array here and put list of actions, anyway you still can put all actions in erb string
- Add I18n support for labels
- Add checkboxes as very left columnt (setup false by default)
- Add place for custom button to execute action an all checked lines.
- Fork it
- Create your feature branch (git checkout -b feature)
- Add some tests.
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin feature)
- Create new Pull Request