diff options
author | Peter Kozak <spag@golwen.net> | 2013-04-29 15:11:02 +0200 |
---|---|---|
committer | Peter Kozak <spag@golwen.net> | 2013-04-29 15:11:02 +0200 |
commit | 9d9bf18ab11aa67e967b09f774af5c651f6064ce (patch) | |
tree | defc6a3bce1a29db5ae704cda4973926a5f9e3d7 | |
parent | 1cc85875f35b69c31b25b7d426439f38e6936893 (diff) |
pagination and sorting added
-rw-r--r-- | app/controllers/users_controller.rb | 14 |
1 files changed, 14 insertions, 0 deletions
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 |