Splashlin
Splashlin

Reputation: 7585

Ruby on Rails Tables Gem

Does anyone know any good gems that can be used to create tables for Ruby on Rails apps. I am looking for something that has built in sorting, AJAX searches, etc.

Upvotes: 3

Views: 4054

Answers (3)

Gazza
Gazza

Reputation: 3141

check out thoughtbot's sortable_table: http://github.com/thoughtbot/sortable_table

Pop 'sortable_attributes' in your controller:

class UsersController < Admin::BaseController
  sortable_attributes :name, :email, :age, :group => "groups.name"

  def index
    @users = User.paginate :page => params[:page], :order => sort_order
  end
end

Pop some helpers in your view:

<h1>Users</h1>
<table>
  <tr>
    <%= sortable_table_header :name => "Name",  :sort => "name" %>
    <%= sortable_table_header :name => "Email", :sort => "email" %>
    <%= sortable_table_header :name => "Age",   :sort => "age" %>
    <%= sortable_table_header :name => "Group", :sort => "group" %>
  </tr>
  <% @users.each do |user| %>
    <tr>
      <td><%= html_escape(user.name) %></td>
      <td><%= html_escape(user.email) %></td>
      <td><%= html_escape(user.age) %></td>
      <td><%= html_escape(user.group.name) %></td>
    </tr>
  <% end %>
</table>

done :)

UPDATE (June 2012): The owner of this gem has marked it as deprecated and unsupported.

Upvotes: 3

Bogdan Gusiev
Bogdan Gusiev

Reputation: 8305

You also could try datagrid gem that can create table with sortable columns and filters.

Upvotes: 3

Eimantas
Eimantas

Reputation: 49354

Looks like active-scaffold gem: http://activescaffold.com/

Upvotes: 0

Related Questions