diff options
author | Marcel Molina <marcel@vernix.org> | 2007-12-05 17:33:18 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2007-12-05 17:33:18 +0000 |
commit | a23bea7c0d16d159b38650770baafd0c09d2ca78 (patch) | |
tree | 83ec8b16bc68c839c2b4101fd4a1a84ce1f1e48c /activerecord/lib/active_record | |
parent | a7e6e009c93302f77b7a601f53fe88d63210c433 (diff) | |
download | rails-a23bea7c0d16d159b38650770baafd0c09d2ca78.tar.gz rails-a23bea7c0d16d159b38650770baafd0c09d2ca78.tar.bz2 rails-a23bea7c0d16d159b38650770baafd0c09d2ca78.zip |
Document API for create's attributes parameter and provide examples. Closes #7915 [fearoffish]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8296 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 81ee16e380..5330899ece 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -474,8 +474,17 @@ module ActiveRecord #:nodoc: false end - # Creates an object, instantly saves it as a record (if the validation permits it), and returns it. If the save - # fails under validations, the unsaved object is still returned. + # Creates an object (or multiple objects) and saves it to the database, if validations pass. + # The resulting object is returned whether the object was saved successfully to the database or not. + # + # The +attributes+ parameter can be either be a Hash or an Array of Hashes. These Hashes describe the + # attributes on the objects that are to be created. + # + # ==== Examples + # # Create a single new object + # User.create(:first_name => 'Jamie') + # # Create an Array of new objects + # User.create([{:first_name => 'Jamie'}, {:first_name => 'Jeremy'}]) def create(attributes = nil) if attributes.is_a?(Array) attributes.collect { |attr| create(attr) } |