Created
March 23, 2010 15:23
-
-
Save house9/341290 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see http://gist.github.com/341278 (sort_index.rb) | |
# see http://gist.github.com/341295 (sort_index_view_usage.html.erb) | |
# this example is an employees controller and using the will_paginate plugin | |
# however code should work fine with a standard ActiveRecord#find(:all, :order => ... | |
# put the sort_index.rb code in your rails lib directory | |
class EmployeesController < ApplicationController | |
# index sort constant config for sorting index action | |
# default is order by updated_at DESC | |
INDEX_SORT = SortIndex::Config.new( | |
{'updated_at' => 'updated_at'}, | |
{ | |
'full_name' => 'UPPER(first_name), UPPER(last_name)', | |
'email' => 'email' | |
} | |
#, optionally SortIndex::SORT_KEY_ASC | |
) | |
def index | |
@sortable = SortIndex::Sortable.new(params, INDEX_SORT) | |
@employees = Employee.paginate :page => params[:page], :order => @sortable.order | |
# render index.html.erb | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment