Flowdock
method

new

Importance_1
Ruby on Rails latest stable (v5.2.3) - 0 notes - Class: ActiveRecord::Relation
new(attributes = nil, &block) public

Initializes new record from relation while maintaining the current scope.

Expects arguments in the same format as ActiveRecord::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
Show source
Register or log in to add new notes.