views:

1545

answers:

1

I am using will_paginate and sort helper for pagination and sorting resp.. But im facing one problem while sorting that when im on page 2 or 3 or any other page than first page. It redirects to the first page and sorts the first page only. please help me how to sort all the records and go back to page where I was.

+1  A: 

What's the reason you need to go back to the page (2 or 3)? Records will change position and probabily page so you will not find them at the same place.

so why you don't change only the :order value (ex. from 'firstname DESC' to 'lastname DESC) when you call the action again?

# people_controller.rb
def index
  @people = People.search(params[:my_order], params[:page])
end

# models/people.rb
def self.search(my_order, page)
  paginate :per_page => 10, :page => page,
           :conditions => ['job like ?', "Driver"],
           :order => "%#{my_order}%"
end
baijiu