Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667class GamesController < ApplicationController before_action :set_game, only: [:show, :edit, :update] before_action :authorize, only: [:edit, :update] before_action :set_query, only: [:index] before_action :set_games, only: [:index]
def index end
def show @on_game_page = true @category = @game.categories.joins(:runs).group('categories.id').order('count(runs.id) desc').first if @category.nil? render :not_found, status: 404 return end render template: 'games/categories/show' end
def edit end
def update shortname = params[@game.id.to_s][:shortname].presence
if @game.update(shortname: shortname) redirect_to( edit_game_path(@game), notice: if shortname.present? "Saved! #{@game.name} now has the shortname '#{@game.shortname}'." else "Saved! #{@game.name} no longer has a shortname." end ) else redirect_to( edit_game_path(@game), alert: "Couldn't update #{@game.name}'s shortname to '#{@game.shortname}'." ) end end
private
def authorize if cannot?(:edit, @game) redirect_to game_path(@game), alert: "You don't have permission to do that." end end
def set_game @game = Game.find_by(shortname: params[:game]) || Game.find_by(id: params[:game])
if @game.nil? redirect_to games_path(q: params[:game]) end end
def set_query @query = params[:q].strip if params[:q].present? end
def set_games @games = @query.present? ? Game.search(@query).includes(:categories) : [] endend