diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2013-05-13 10:54:59 +0300 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-16 13:31:35 -0700 |
commit | 711097e6a5af61a31a0547223038a4b5e1d59366 (patch) | |
tree | 32ba32fbfb99662a4f14a889846f1500f3f31c90 /activerecord/lib/active_record/errors.rb | |
parent | e38c93a120de84ee5c2f22e9da942233a7edd22e (diff) | |
download | rails-711097e6a5af61a31a0547223038a4b5e1d59366.tar.gz rails-711097e6a5af61a31a0547223038a4b5e1d59366.tar.bz2 rails-711097e6a5af61a31a0547223038a4b5e1d59366.zip |
Add more data to AR::UnknownAttributeError
begin
Topic.new("hello" => "world")
rescue ActiveRecord::UnknownAttributeError => e
e.record # => #<Topic ... >
e.attribute # => "hello"
end
Diffstat (limited to 'activerecord/lib/active_record/errors.rb')
-rw-r--r-- | activerecord/lib/active_record/errors.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index cd31147414..017b8bace6 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -159,6 +159,15 @@ module ActiveRecord # Raised when unknown attributes are supplied via mass assignment. class UnknownAttributeError < NoMethodError + + attr_reader :record, :attribute + + def initialize(record, attribute) + @record = record + @attribute = attribute.to_s + super("unknown attribute: #{attribute}") + end + end # Raised when an error occurred while doing a mass assignment to an attribute through the |