diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb index 6c68483..6d4af17 100644 --- a/app/models/custom_value.rb +++ b/app/models/custom_value.rb @@ -19,6 +19,8 @@ class CustomValue < ActiveRecord::Base belongs_to :custom_field belongs_to :customized, :polymorphic => true + validate :validate_custom_value + def after_initialize if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?)) self.value ||= custom_field.default_value @@ -47,7 +49,7 @@ class CustomValue < ActiveRecord::Base end protected - def validate + def validate_custom_value if value.blank? errors.add(:value, :blank) if custom_field.is_required? and value.blank? else