Fix contest creation
This commit is contained in:
@@ -56,12 +56,15 @@ class ContestsController < ApplicationController
|
|||||||
authorize :contest
|
authorize :contest
|
||||||
|
|
||||||
@contest = Contest.new
|
@contest = Contest.new
|
||||||
|
@title = I18n.t("contests.new.title")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
authorize :contest
|
authorize :contest
|
||||||
|
|
||||||
@contest = Contest.new(new_contest_params)
|
@contest = Contest.new(new_contest_params)
|
||||||
|
@contest.lang = @current_user.lang
|
||||||
|
@contest.ranking_mode = "actual"
|
||||||
@contest.user_id = current_user.id
|
@contest.user_id = current_user.id
|
||||||
if @contest.save
|
if @contest.save
|
||||||
redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.new.notice")
|
redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.new.notice")
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ class Contest < ApplicationRecord
|
|||||||
|
|
||||||
friendly_id :name, use: :slugged
|
friendly_id :name, use: :slugged
|
||||||
|
|
||||||
before_save :add_duration_seconds
|
before_save :add_duration_seconds, if: -> { duration.present? }
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :lang, inclusion: { in: Languages::AVAILABLE_LANGUAGES.map { |lang| lang[:id] } }
|
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 :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
|
generates_token_for :token
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ html
|
|||||||
= msg
|
= msg
|
||||||
|
|
||||||
h1.mb-4
|
h1.mb-4
|
||||||
- if @contest
|
- if @contest && @contest.id.present?
|
||||||
= @contest.name
|
= @contest.name
|
||||||
- if active_page("/public") == "active" && @action_path
|
- if active_page("/public") == "active" && @action_path
|
||||||
a.ms-4.btn.btn-primary href=@action_path style="margin-top: -6px"
|
a.ms-4.btn.btn-primary href=@action_path style="margin-top: -6px"
|
||||||
@@ -52,7 +52,7 @@ html
|
|||||||
- else
|
- else
|
||||||
= @title
|
= @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"
|
= render "contest_nav"
|
||||||
|
|
||||||
= yield
|
= yield
|
||||||
Reference in New Issue
Block a user