Ensure puzzle uniqueness per contestant validation error is shown
This commit is contained in:
parent
9862f0c74b
commit
b6da55723d
@ -36,7 +36,8 @@ class Completion < ApplicationRecord
|
||||
before_save :add_time_seconds
|
||||
|
||||
validates :display_time_from_start, presence: true, format: { with: /\A(((\d\d|\d):\d\d|\d\d|\d):\d\d|\d\d|\d)\z/ }
|
||||
validates :puzzle_id, uniqueness: { scope: :contestant }
|
||||
validates :contestant_id, uniqueness: { scope: :puzzle }, if: -> { contest.puzzles.size == 1 }
|
||||
validates :puzzle_id, uniqueness: { scope: :contestant }, if: -> { contest.puzzles.size > 1 }
|
||||
|
||||
def add_time_seconds
|
||||
arr = display_time_from_start.split(":")
|
||||
|
@ -82,6 +82,8 @@ en:
|
||||
models:
|
||||
completion:
|
||||
attributes:
|
||||
contestant_id:
|
||||
taken: "This contestant has already completed the puzzle"
|
||||
display_time_from_start:
|
||||
blank: Mandatory
|
||||
invalid: "Allowed formats: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx"
|
||||
|
@ -53,6 +53,8 @@ fr:
|
||||
models:
|
||||
completion:
|
||||
attributes:
|
||||
contestant_id:
|
||||
taken: "Ce.tte participant.e a déjà complété le puzzle"
|
||||
display_time_from_start:
|
||||
blank: Obligatoire
|
||||
invalid: "Formats autorisés: xx:xx:xx, x:xx:xx, xx:xx, x:xx, xx"
|
||||
|
Loading…
x
Reference in New Issue
Block a user