aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-10-09 01:52:24 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-10-09 01:52:24 +0000
commit55aab5b8acb72967228dc38f6432e0f126a94d77 (patch)
tree6e0e028919bf4ad819d9c5d48f5b664704a282d3 /activerecord/lib/active_record
parent9fd88d793998ea3a15a916ce7175f1bb2cd264fe (diff)
downloadrails-55aab5b8acb72967228dc38f6432e0f126a94d77.tar.gz
rails-55aab5b8acb72967228dc38f6432e0f126a94d77.tar.bz2
rails-55aab5b8acb72967228dc38f6432e0f126a94d77.zip
Added update_attributes! which uses save! to raise an exception if a validation error prevents saving (closes #6192) [jonathan]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5256 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 5d7c30caf9..1cdebd93d9 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1576,6 +1576,12 @@ module ActiveRecord #:nodoc:
self.attributes = attributes
save
end
+
+ # Updates an object just like Base.update_attributes but calls save! instead of save so an exception is raised if the record is invalid.
+ def update_attributes!(attributes)
+ self.attributes = attributes
+ save!
+ end
# Initializes the +attribute+ to zero if nil and adds one. Only makes sense for number-based attributes. Returns self.
def increment(attribute)