new 2

new(*args, &block)
Instance Public methods

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

build

doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.