Module: TableHelper
- Defined in:
- lib/table_for/table.rb,
lib/table_for/column.rb,
lib/table_for/helper.rb,
lib/table_for/version.rb,
lib/table_for_collection.rb,
lib/table_for/simple_column.rb,
lib/table_for/callback_column.rb
Defined Under Namespace
Classes: CallbackColumn, Column, SimpleColumn, Table
Constant Summary collapse
- GEM_NAME =
"table_for_collection"
- VERSION =
"1.0.5"
Instance Method Summary collapse
-
#table_for(records, *args, &proc) ⇒ Object
Simplest examle:.
Instance Method Details
#table_for(records, *args, &proc) ⇒ Object
Simplest examle:
<%= table_for @users do -%>
<% columns :name, :email, :address %>
<% end %>
Simple examle:
<%= table_for @users, :http => { :class => "simple-table", :id => "users" } do -%>
<% column :name %>
<% column :email %>
<% column :address %>
<% end %>
More complex example:
<%= table_for @users do -%>
<% column :login, :title => "User name" %>
<% column :email %>
<% column :title => "Full name" do |user| %>
<% [user.first_name, user.last_name].join(" ") %>
<% end %>
<% column :title => "Actions" do |user| %>
<% link_to "Show", user %>
<% link_to "Delete", user, :method => :delete %>
<% end %>
<% end %>
30 31 32 33 34 35 36 37 |
# File 'lib/table_for/helper.rb', line 30 def table_for(records, *args, &proc) raise ArgumentError, "Missing block" unless block_given? = args. raise ArgumentError, "Records should have #map method" unless records.respond_to?(:map) t = Table.new(self, records, ) t.instance_eval(&proc) t.draw end |