about summary refs log tree commit diff stats
path: root/app/controllers/games_controller.rb
blob: a1405b9077b25d920527a572dab568517a10f731 (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
      (params[:sort] and Game.column_names.include?(params[:sort])) ? params[:sort] : "started_on"
    end

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