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.
This commit is contained in:
Patrick Gansterer 2020-07-29 09:14:30 +02:00
parent b089b7c186
commit d75b881318

View file

@ -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