diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-13 15:48:14 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-13 15:48:14 -0400 |
commit | b62d43ccde70aa6fccf5341e57a695a2cfb289c1 (patch) | |
tree | 8e612d68c89e8358c80663f2dcfab35f33ba89c3 /app/controllers | |
parent | b6018ad11156d8b38a87dc682064495cd788608c (diff) | |
download | thoughts-b62d43ccde70aa6fccf5341e57a695a2cfb289c1.tar.gz thoughts-b62d43ccde70aa6fccf5341e57a695a2cfb289c1.tar.bz2 thoughts-b62d43ccde70aa6fccf5341e57a695a2cfb289c1.zip |
Game list is sortable
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/games_controller.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 8ddcf24..dcbe226 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb | |||
@@ -1,9 +1,21 @@ | |||
1 | class GamesController < ApplicationController | 1 | class GamesController < ApplicationController |
2 | helper_method :sort_column, :sort_direction | ||
3 | |||
2 | def index | 4 | def index |
3 | @games = Game.order(started_on: :desc) | 5 | @games = Game.order(sort_column + " " + sort_direction) |
4 | 6 | ||
5 | if params[:status] | 7 | if params[:status] |
6 | @games = @games.where(status: params[:status]) | 8 | @games = @games.where(status: params[:status]) |
7 | end | 9 | end |
8 | end | 10 | end |
11 | |||
12 | private | ||
13 | |||
14 | def sort_column | ||
15 | Game.column_names.include?(params[:sort]) ? params[:sort] : "started_on" | ||
16 | end | ||
17 | |||
18 | def sort_direction | ||
19 | %[asc desc].include?(params[:dir]) ? params[:dir] : "asc" | ||
20 | end | ||
9 | end | 21 | end |