instance method create

Ruby on Rails 3.0.20

Since v3.0.20 Last seen in v3.2.22.5 Private

Available in: v3.0.20 v3.1.12 v3.2.22.5

Signature

create()

Creates a record with values matching those of the instance attributes and returns its id.

Source
# File activerecord/lib/active_record/persistence.rb, line 271
    def create
      if self.id.nil? && connection.prefetch_primary_key?(self.class.table_name)
        self.id = connection.next_sequence_value(self.class.sequence_name)
      end

      attributes_values = arel_attributes_values

      new_id = if attributes_values.empty?
        self.class.unscoped.insert connection.empty_insert_statement_value
      else
        self.class.unscoped.insert attributes_values
      end

      self.id ||= new_id

      @new_record = false
      id
    end

Defined in activerecord/lib/active_record/persistence.rb line 271 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::Persistence

Type at least 2 characters to search.

↑↓ navigate · open · esc close