instance method
create!
Ruby on Rails 8.1.2
Since v4.2.9Signature
create!(attributes = nil, &block)
Creates an object (or multiple objects) and saves it to the database, if validations pass. Raises a RecordInvalid error if validations fail, unlike Base#create.
The attributes parameter can be either a Hash or an Array of Hashes. These describe which attributes to be created on the object, or multiple objects when given an Array of Hashes.
Parameters
-
attributesopt = nil -
blockblock
Source
# File activerecord/lib/active_record/persistence.rb, line 50
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
Defined in activerecord/lib/active_record/persistence.rb line 50
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Persistence::ClassMethods