instance method create!

Ruby on Rails 8.0.4

Since v4.2.9

Available in: v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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

attributes opt = nil
block block
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

Type at least 2 characters to search.

↑↓ navigate · open · esc close