From d75b88131868d800b6b5f852161c52b7e6c78d74 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Wed, 29 Jul 2020 09:14:30 +0200 Subject: [PATCH] Set Poll.multi_select_count to default value in model if nil Since multi_select_count depends on the type of poll, we can not require its presence via validates_presence_of, but can use the default value. --- plugins/polls/app/models/poll.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/polls/app/models/poll.rb b/plugins/polls/app/models/poll.rb index ec7b1506..fe5eabdc 100644 --- a/plugins/polls/app/models/poll.rb +++ b/plugins/polls/app/models/poll.rb @@ -23,6 +23,10 @@ class Poll < ActiveRecord::Base include DateTimeAttributeValidate date_time_attribute :starts, :ends + before_save do + self.multi_select_count ||= 0 + end + def available_points return 0...0 if min_points.nil? || max_points.nil? min_points..max_points