diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2014-08-05 18:36:29 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2014-08-05 18:36:29 +0300 |
commit | 977a489cfad70dfd0a6a01c4ef792cf6ac0c9046 (patch) | |
tree | a61d4319c9bda5b26180409834afd654402cdf81 /activerecord/lib/active_record/persistence.rb | |
parent | 3300fdedc748993b378288c6cbc3113885c955ed (diff) | |
download | rails-977a489cfad70dfd0a6a01c4ef792cf6ac0c9046.tar.gz rails-977a489cfad70dfd0a6a01c4ef792cf6ac0c9046.tar.bz2 rails-977a489cfad70dfd0a6a01c4ef792cf6ac0c9046.zip |
Moved #create! method from Validations to Persistence module
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 96e44c2f59..f35865f54c 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -36,6 +36,18 @@ module ActiveRecord end end + # Creates an object just like Base.create but calls <tt>save!</tt> instead of +save+ + # so an exception is raised if the record is invalid. + def create!(attributes = nil, &block) + if attributes.is_a?(Array) + attributes.collect { |attr| create!(attr, &block) } + else + object = new(attributes, &block) + object.save! + object + end + end + # Given an attributes hash, +instantiate+ returns a new instance of # the appropriate class. Accepts only keys as strings. # |