class GamesController < ApplicationController
  def index
    @days = Game.scheduled.display_order.group_by{|x| x.scheduled_at.to_date }
  end

  def show
    @game = Game.find(params[:id])
    @comment = Comment.new
    @video = @game.videos.new
  end

  def upvote
    authenticate_user!
    @game = Game.find(params[:id])
    @game.upvote_by(current_user)
    redirect_to games_path
  end

  def unupvote
    authenticate_user!
    @game = Game.find(params[:id])
    @game.unvote_by(current_user)
    redirect_to games_path
  end

  def upload
    uploaded_io = params[:game][:thumbnail]
    File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
      file.write(uploaded_io.read)
    end
  end

  private
  def game_params
    params.require(:game).permit(:title, :thumbnail, :description, :status, :link, :platform)
  end
end

class GamesController < ApplicationController
  def index
    @days = Game.scheduled.display_order.group_by{|x| x.scheduled_at.to_date }
  end

  def show
    @game = Game.find(params[:id])
    @comment = Comment.new
    @video = @game.videos.new
  end

  def upvote
    authenticate_user!
    @game = Game.find(params[:id])
    @game.upvote_by(current_user)
    redirect_to :back
  end

  def unupvote
    authenticate_user!
    @game = Game.find(params[:id])
    @game.unvote_by(current_user)
    redirect_to :back
  end

  def upload
    uploaded_io = params[:game][:thumbnail]
    File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'wb') do |file|
      file.write(uploaded_io.read)
    end
  end

  private
  def game_params
    params.require(:game).permit(:title, :thumbnail, :description, :status, :link, :platform)
  end
end

Fix voting from game page.
Fix voting from game page.
