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'}])
Source Code
# File active_record/base.rb, line 567 def create(attributes = nil) if attributes.is_a?(Array) attributes.collect { |attr| create(attr) } else object = new(attributes) object.save object end end
<code/>and<pre/>for code samples.