From 55aab5b8acb72967228dc38f6432e0f126a94d77 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 9 Oct 2006 01:52:24 +0000 Subject: 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 --- activerecord/lib/active_record/base.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activerecord/lib') 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) -- cgit v1.2.3