Method: ActiveRecord::Relation#new

Defined in:
lib/ocean-dynamo/active_record_stuff/relation.rb

#new(*args, &block) ⇒ Object Also known as: build

Initializes new record from relation while maintaining the current scope.

Expects arguments in the same format as Base.new.

users = User.where(name: 'DHH')
user = users.new # => #<User id: nil, name: "DHH", created_at: nil, updated_at: nil>

You can also pass a block to new with the new record as argument:

user = users.new { |user| user.name = 'Oscar' }
user.name # => Oscar


95
96
97
# File 'lib/ocean-dynamo/active_record_stuff/relation.rb', line 95

def new(*args, &block)
  scoping { @klass.new(*args, &block) }
end