From 8cd389750c4cffd6a2552f6ab28a274410f69c34 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 18 Nov 2023 09:40:05 -0500 Subject: uniqueness on names per puzzle --- app/controllers/wittle/puzzles_controller.rb | 2 +- app/models/wittle/score.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index 9d846f9..a937aa1 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb @@ -93,7 +93,7 @@ module Wittle raise ActiveRecord::RecordNotFound unless @puzzle.latest? - @puzzle.scores.create!(name: params[:name], ip: request.ip, seconds_taken: (params.include? :time) ? params[:time] : nil) + @puzzle.scores.create(name: params[:name], ip: request.ip, seconds_taken: (params.include? :time) ? params[:time] : nil) redirect_to @puzzle end diff --git a/app/models/wittle/score.rb b/app/models/wittle/score.rb index be00fda..54d2b89 100644 --- a/app/models/wittle/score.rb +++ b/app/models/wittle/score.rb @@ -4,5 +4,6 @@ module Wittle validates :name, presence: true validates :ip, presence: true + validates_uniqueness_of :name, scope: :puzzle_id end end -- cgit 1.4.1