method
first_or_initialize
v5.2.3 -
Show latest stable
- Class:
ActiveRecord::Relation
first_or_initialize(attributes = nil, &block)public
No documentation available.
# File activerecord/lib/active_record/relation.rb, line 111
def first_or_initialize(attributes = nil, &block) # :nodoc:
first || new(attributes, &block)
end 1Note
Description
Selects the first record within a relation if it exists, otherwise creates a new record with the optional attributes.