Setup I18n for titles
This commit is contained in:
parent
26b8064553
commit
497768610d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -4,7 +4,6 @@ class SessionsController < ApplicationController
|
||||
before_action :skip_authorization
|
||||
|
||||
def new
|
||||
@title = "Login"
|
||||
end
|
||||
|
||||
def create
|
||||
|
@ -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
|
||||
|
@ -28,4 +28,39 @@
|
||||
# enabled: "ON"
|
||||
|
||||
en:
|
||||
hello: "Hello world"
|
||||
completions:
|
||||
edit:
|
||||
title: "Edit completion"
|
||||
new:
|
||||
title: "New completion"
|
||||
contests:
|
||||
edit:
|
||||
title: "Edit contest settings"
|
||||
index:
|
||||
title: "Welcome %{username}!"
|
||||
new:
|
||||
title: "New jigsaw puzzle competition"
|
||||
scoreboard:
|
||||
title: "%{name}"
|
||||
show:
|
||||
title: "%{name}"
|
||||
contestants:
|
||||
edit:
|
||||
title: "Contestant"
|
||||
new:
|
||||
title: "New contestant"
|
||||
puzzles:
|
||||
edit:
|
||||
title: "Edit contest puzzle"
|
||||
new:
|
||||
title: "New contest puzzle"
|
||||
sessions:
|
||||
new:
|
||||
title: "Login to the Public Scoreboard app"
|
||||
users:
|
||||
edit:
|
||||
title: "My settings"
|
||||
index:
|
||||
title: "All users"
|
||||
new:
|
||||
title: "New user"
|
||||
|
@ -10,7 +10,7 @@ RSpec.feature "Login", type: :feature do
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
|
||||
expect(page).not_to have_content("Login")
|
||||
expect(page).not_to have_content(I18n.t("sessions.new.title"))
|
||||
end
|
||||
|
||||
it "should fail to log in the user with an incorrect email address" do
|
||||
@ -19,7 +19,7 @@ RSpec.feature "Login", type: :feature do
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
|
||||
expect(page).to have_content("Login")
|
||||
expect(page).to have_content(I18n.t("sessions.new.title"))
|
||||
end
|
||||
|
||||
it "should fail to log in the user with an incorrect password" do
|
||||
@ -28,7 +28,7 @@ RSpec.feature "Login", type: :feature do
|
||||
fill_in "Password", with: Faker::Internet.unique.password
|
||||
click_button "Sign in"
|
||||
|
||||
expect(page).to have_content("Login")
|
||||
expect(page).to have_content(I18n.t("sessions.new.title"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ RSpec.feature "Users", type: :feature do
|
||||
it "should not be able to see the user list" do
|
||||
visit users_path
|
||||
|
||||
expect(page).not_to have_content("All users")
|
||||
expect(page).not_to have_content(I18n.t("users.index.title"))
|
||||
end
|
||||
|
||||
it "should be able to create a new contest" do
|
||||
@ -26,16 +26,16 @@ RSpec.feature "Users", type: :feature do
|
||||
|
||||
click_link "Create a new contest"
|
||||
|
||||
expect(page).to have_content("New jigsaw puzzle competition")
|
||||
expect(page).to have_content(I18n.t("contests.new.title"))
|
||||
end
|
||||
|
||||
it "should be able to open an existing contest" do
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content(contest.name)
|
||||
find("div.card", text: contest.name).find("a").click()
|
||||
find("div.card", text: contest.name).find("a").click
|
||||
|
||||
expect(page).to have_content("Edit contest")
|
||||
expect(page).to have_content(I18n.t("contests.show.title", name: contest.name))
|
||||
end
|
||||
end
|
||||
|
||||
@ -56,7 +56,7 @@ RSpec.feature "Users", type: :feature do
|
||||
it "should be able to see the user list" do
|
||||
visit users_path
|
||||
|
||||
expect(page).to have_content("All users")
|
||||
expect(page).to have_content(I18n.t("users.index.title"))
|
||||
expect(page).to have_content(user.username)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user