instance method
new
Ruby on Rails 4.1.16
Since v3.0.20Signature
new(*args, &block)
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
Parameters
-
argsrest -
blockblock
Source
# File activerecord/lib/active_record/relation.rb, line 114
def new(*args, &block)
scoping { @klass.new(*args, &block) }
end
Defined in activerecord/lib/active_record/relation.rb line 114
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation