views:

168

answers:

2

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.

A: 

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

Eimantas
A: 

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 :)