about summary refs log tree commit diff stats
path: root/app/controllers/games_controller.rb
blob: dcbe2265099cf5002882b33d267bd4f498e617f8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class GamesController < ApplicationController
  helper_method :sort_column, :sort_direction

  def index
    @games = Game.order(sort_column + " " + sort_direction)

    if params[:status]
      @games = @games.where(status: params[:status])
    end
  end

  private

    def sort_column
      Game.column_names.include?(params[:sort]) ? params[:sort] : "started_on"
    end

    def sort_direction
      %[asc desc].include?(params[:dir]) ? params[:dir] : "asc"
    end
end