Sha256: c39cfe6865a06556a748e850fef8a261dbe74508714ab0014ab70e5c1ba59ed9
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
h1. Sortable Table Sort HTML tables in a Rails app. h2. Install script/plugin install git://github.com/dancroak/sortable_table.git In test/test_helper.rb: class Test::Unit::TestCase include SortableTable::Test::TestHelper end 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 h2. Conventions params[:sort] and params[:order] h2. Examples Use the sortable_attributes macro to list the... sortable attributes. Then, in your index action, pass the sort_order method to your usual order parameter for will paginate or named scope call. class UsersController < Admin::BaseController sortable_attributes :name, :email def index @users = User.paginate :page => params[:page], :order => sort_order end end Time-saving Shoulda macros for your tests: class UsersControllerTest < ActionController::TestCase context 'GET to index with sort and order params' do setup do 5.times do |each| Factory :user, :name => "name #{each}", :email => "email#{each}@example.com" end end should_sort_by :name should_sort_by :email end end And some sugar for your views: %h1 Users %table %tr = sortable_table_header :name => 'Name', :sort => 'name' = sortable_table_header :name => 'E-mail', :sort => 'email' - @users.each do |each| %tr %td= each.name %td= each.email Authors ------- Dan Croak, Joe Ferris, and Boston.rb. Copyright (c) 2008 Dan Croak, released under the MIT license
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
dancroak-sortable_table-0.2.0 | README.textile |
ryana-sortable_table-0.2.0 | README.textile |