diff options
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/write.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/write.rb b/activerecord/lib/active_record/attribute_methods/write.rb index fde55b95da..8c6fa90a28 100644 --- a/activerecord/lib/active_record/attribute_methods/write.rb +++ b/activerecord/lib/active_record/attribute_methods/write.rb @@ -28,11 +28,14 @@ module ActiveRecord @attributes_cache.delete(attr_name) column = column_for_attribute(attr_name) - if column || @attributes.has_key?(attr_name) - @attributes[attr_name] = type_cast_attribute_for_write(column, value) - else - raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'" + unless column || @attributes.has_key?(attr_name) + ActiveSupport::Deprecation.warn( + "You're trying to create an attribute `#{attr_name}'. Writing arbitrary " \ + "attributes on a model is deprecated. Please just use `attr_writer` etc." + ) end + + @attributes[attr_name] = type_cast_attribute_for_write(column, value) end alias_method :raw_write_attribute, :write_attribute |