From 9d9bf18ab11aa67e967b09f774af5c651f6064ce Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 29 Apr 2013 15:11:02 +0200 Subject: pagination and sorting added --- app/controllers/users_controller.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'app/controllers/users_controller.rb') diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ea8ed69..99e2fc5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,8 +5,14 @@ class UsersController < ApplicationController before_filter :set_and_authorize_parent before_filter :spread_breadcrumbs + + helper_method :sort_column, :sort_descending def index + @users = User.order(sort_column + ' ' + (sort_descending ? 'DESC' : 'ASC')).paginate( + :page => @pagination_page_number, + :per_page => GsParameter.get('DEFAULT_PAGINATION_ENTRIES_PER_PAGE') + ) end def show @@ -88,4 +94,12 @@ class UsersController < ApplicationController end end + def sort_descending + params[:desc].to_s == 'true' + end + + def sort_column + User.column_names.include?(params[:sort]) ? params[:sort] : 'id' + end + end -- cgit v1.2.3