# sortable_table **Repository Path**: mirrors_thoughtbot/sortable_table ## Basic Information - **Project Name**: sortable_table - **Description**: Sort HTML tables in your Rails app. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-18 - **Last Updated**: 2026-03-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README DEPRECATED ========== Thoughtbot is no longer supporting this project. We have not used it a long time. If you would like to maintain it, please email hello@thoughtbot.com. Sortable Table ============== Sort HTML tables in your Rails app. Install ------- script/plugin install git://github.com/thoughtbot/sortable_table.git In app/controllers/application_controller.rb: class ApplicationController < ActionController::Base include SortableTable::App::Controllers::ApplicationController end In app/helpers/application_helper.rb: module ApplicationHelper include SortableTable::App::Helpers::ApplicationHelper end Testing ------- context "enough Users to sort" do setup do 5.times { Factory :user } end should_sort_by_attributes :name, :email, :age, :group => "groups.name" context "GET to #index" do setup { get :index } should_display_sortable_table_header_for :name, :email, :age, :group end end This is the common case for a RESTful UsersController. * should_sort_by_attributes tests that the controller's index action can sort by the attributes. * should_display_sortable_header_for tests that a sortable header displays for the attributes. 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 sortable_attributes defines a sort_order method that gets called in your action. If the index action is rendered without a params[:sort] option, @users will be sorted by :name, the first option in the list of sortable_attributes. View ----
| <%= html_escape(user.name) %> | <%= html_escape(user.email) %> | <%= html_escape(user.age) %> | <%= html_escape(user.group.name) %> |