instance method first_or_initialize

Ruby on Rails 3.2.22.5

Since v3.2.22.5 Last seen in v3.2.22.5

Signature

first_or_initialize(attributes = nil, options = {}, &block)

Like first_or_create but calls new instead of create.

Expects arguments in the same format as Base.new.

Parameters

attributes opt = nil
options opt = {}
block block
Source
# File activerecord/lib/active_record/relation.rb, line 131
    def first_or_initialize(attributes = nil, options = {}, &block)
      first || new(attributes, options, &block)
    end

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

Defined in ActiveRecord::Relation

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close