-
Notifications
You must be signed in to change notification settings - Fork 13
Getting started
lunich edited this page Nov 17, 2011
·
1 revision
This plugin let you create tables for your collections using easy interface. Here is simple example:
= table_for @users
= columns :id, :full_name, :email, :address
This code will generate table based on the @users
collection. @users
must respond to each
method. Elements of @users
objects must or respond to :id
, :full_name
, :email
, :address
or have such keys (being Hash
object, of course).
So @users
can be one of:
@users = User.all
or:
@users = User.where(:role => "admin").paginate(:per_page => 10, :page => 2)
or:
@users = [
{ :id => 1, :full_name => "John Smith", :email => "[email protected]", :address => "101, Spear St., LA, CA" },
{ :id => 2, :full_name => "Jack Smith", :email => "[email protected]", :address => "101, Spear St., LA, CA" },
]
In this example table_for
will generate following HTML code:
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Smith</td>
<td>[email protected]</td>
<td>100 Spear St., NY, USA</td>
</tr>
</tbody>
</table>