about summary refs log tree commit diff stats
path: root/app/controllers/games_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/games_controller.rb')
-rw-r--r--app/controllers/games_controller.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb new file mode 100644 index 0000000..a1405b9 --- /dev/null +++ b/app/controllers/games_controller.rb
@@ -0,0 +1,21 @@
1class GamesController < ApplicationController
2 helper_method :sort_column, :sort_direction
3
4 def index
5 @games = Game.order(sort_column + " " + sort_direction)
6
7 if params[:status]
8 @games = @games.where(status: params[:status])
9 end
10 end
11
12 private
13
14 def sort_column
15 (params[:sort] and Game.column_names.include?(params[:sort])) ? params[:sort] : "started_on"
16 end
17
18 def sort_direction
19 (params[:dir] and %[asc desc].include?(params[:dir])) ? params[:dir] : "asc"
20 end
21end