diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 8628bc5..689c7e9 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -56,12 +56,15 @@ class ContestsController < ApplicationController authorize :contest @contest = Contest.new + @title = I18n.t("contests.new.title") end def create authorize :contest @contest = Contest.new(new_contest_params) + @contest.lang = @current_user.lang + @contest.ranking_mode = "actual" @contest.user_id = current_user.id if @contest.save redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.new.notice") diff --git a/app/models/contest.rb b/app/models/contest.rb index 8001c30..7464065 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -39,12 +39,12 @@ class Contest < ApplicationRecord friendly_id :name, use: :slugged - before_save :add_duration_seconds + before_save :add_duration_seconds, if: -> { duration.present? } validates :name, presence: true validates :lang, inclusion: { in: Languages::AVAILABLE_LANGUAGES.map { |lang| lang[:id] } } validates :ranking_mode, inclusion: { in: Ranking::AVAILABLE_RANKING_MODES.map { |lang| lang[:id] } } - validates :duration, format: { with: /\A(\d\d:\d\d|\d:\d\d)\z/ } + validates :duration, format: { with: /\A(\d\d:\d\d|\d:\d\d)\z/ }, if: -> { duration.present? } generates_token_for :token diff --git a/app/views/layouts/authenticated.html.slim b/app/views/layouts/authenticated.html.slim index f66a069..33558c2 100644 --- a/app/views/layouts/authenticated.html.slim +++ b/app/views/layouts/authenticated.html.slim @@ -44,7 +44,7 @@ html = msg h1.mb-4 - - if @contest + - if @contest && @contest.id.present? = @contest.name - if active_page("/public") == "active" && @action_path a.ms-4.btn.btn-primary href=@action_path style="margin-top: -6px" @@ -52,7 +52,7 @@ html - else = @title - - if @contest && active_page("/public") != "active" + - if @contest && active_page("/public") != "active" && active_page("/contests/new") != "active" && active_page("/contests/create") != "active" && active_page("/contests") == "active" = render "contest_nav" = yield \ No newline at end of file