about summary refs log blame commit diff stats
path: root/app/controllers/games_controller.rb
blob: a1405b9077b25d920527a572dab568517a10f731 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                             
                                             
           
                                                           


                                                    
     


                   
                                                                                                  

                      
                                                                                  
       
   
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