aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validator.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb
index 1d2888a818..21339b628e 100644
--- a/activemodel/lib/active_model/validator.rb
+++ b/activemodel/lib/active_model/validator.rb
@@ -167,6 +167,13 @@ module ActiveModel
def should_validate?(record) # :nodoc:
!record.persisted? || record.changed? || record.marked_for_destruction?
end
+
+ # Always validate the record if the attribute is a virtual attribute.
+ # We have no way of knowing that the record was changed if the attribute
+ # does not exist in the database.
+ def unknown_attribute?(record, attribute) # :nodoc:
+ !record.attributes.include?(attribute.to_s)
+ end
end
# +BlockValidator+ is a special +EachValidator+ which receives a block on initialization