Setup I18n for titles
All checks were successful
CI / scan_ruby (push) Successful in 17s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 11s
CI / test (push) Successful in 26s

This commit is contained in:
sto
2025-03-27 12:15:27 +01:00
parent 26b8064553
commit 497768610d
10 changed files with 51 additions and 37 deletions

View File

@@ -13,7 +13,10 @@ class ApplicationController < ActionController::Base
private
def set_title
@title = "Public scoreboard"
t_action_name = action_name
t_action_name = "new" if action_name == "create"
t_action_name = "edit" if action_name == "update"
@title = I18n.t("#{controller_name}.#{t_action_name}.title")
end
def set_current_user

View File

@@ -7,8 +7,6 @@ class CompletionsController < ApplicationController
def edit
authorize @contest
@title = "Edit completion"
end
def new
@@ -18,7 +16,6 @@ class CompletionsController < ApplicationController
if params[:contestant_id]
@completion.contestant_id = params[:contestant_id]
end
@title = "New completion"
end
def create
@@ -32,7 +29,6 @@ class CompletionsController < ApplicationController
else
logger = Logger.new(STDOUT)
logger.info(@completion.errors)
@title = "New completion"
render :new, status: :unprocessable_entity
end
end
@@ -47,7 +43,6 @@ class CompletionsController < ApplicationController
extend_completions!(@completion.contestant)
redirect_to @contest
else
@title = "Edit completion"
render :edit, status: :unprocessable_entity
end
end

View File

@@ -5,15 +5,12 @@ class ContestantsController < ApplicationController
def edit
authorize @contest
@title = "Contestant"
end
def new
authorize @contest
@contestant = Contestant.new
@title = "New contestant"
end
def create
@@ -24,7 +21,6 @@ class ContestantsController < ApplicationController
if @contestant.save
redirect_to contest_path(@contest)
else
@title = "New contestant"
render :new, status: :unprocessable_entity
end
end
@@ -35,7 +31,6 @@ class ContestantsController < ApplicationController
if @contestant.update(contestant_params)
redirect_to @contest
else
@title = "Contestant"
render :edit, status: :unprocessable_entity
end
end

View File

@@ -6,13 +6,13 @@ class ContestsController < ApplicationController
authorize :contest
@contests = current_user.contests
@title = "Welcome #{current_user.username}!"
@title = I18n.t("contests.index.title", username: current_user.username)
end
def show
authorize @contest
@title = @contest.name
@title = I18n.t("contests.show.title", name: @contest.name)
@contestants = @contest.contestants.order(:name)
@puzzles = @contest.puzzles.order(:id)
set_badges
@@ -20,15 +20,12 @@ class ContestsController < ApplicationController
def edit
authorize @contest
@title = "Edit contest settings"
end
def new
authorize :contest
@contest = Contest.new
@title = "New jigsaw puzzle competition"
end
def create
@@ -65,7 +62,7 @@ class ContestsController < ApplicationController
end
authorize @contest
@title = @contest.name
@title = I18n.t("contests.scoreboard.title", name: @contest.name)
@contestants = @contest.contestants.order(:name)
@puzzles = @contest.puzzles.order(:id)
render :scoreboard

View File

@@ -4,15 +4,12 @@ class PuzzlesController < ApplicationController
def edit
authorize @contest
@title = "Edit contest puzzle"
end
def new
authorize @contest
@puzzle = Puzzle.new
@title = "New contest puzzle"
end
def create
@@ -23,7 +20,6 @@ class PuzzlesController < ApplicationController
if @puzzle.save
redirect_to contest_path(@contest)
else
@title = "New contest puzzle"
render :new, status: :unprocessable_entity
end
end
@@ -34,7 +30,6 @@ class PuzzlesController < ApplicationController
if @puzzle.update(puzzle_params)
redirect_to @contest
else
@title = "Edit contest puzzle"
render :edit, status: :unprocessable_entity
end
end

View File

@@ -4,7 +4,6 @@ class SessionsController < ApplicationController
before_action :skip_authorization
def new
@title = "Login"
end
def create

View File

@@ -4,14 +4,11 @@ class UsersController < ApplicationController
def index
authorize :user
@title = "All users"
@users = User.all
end
def edit
authorize @user
@title = "My settings"
end
def update
@@ -33,7 +30,6 @@ class UsersController < ApplicationController
def new
authorize :user
@title = "New user"
@user = User.new()
end
@@ -44,7 +40,6 @@ class UsersController < ApplicationController
if @user.save
redirect_to users_path
else
@title = "New user"
render :new, status: :unprocessable_entity
end
end