简体   繁体   中英

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.

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.

您还可以尝试使用可以创建具有可排序列和过滤器的表的datagrid gem

看起来像active-scaffold gem: http//activescaffold.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM