instance method
create
Ruby on Rails 4.2.9
Since v3.0.20Signature
create(*args, &block)
Tries to create a new record with the same scoped attributes defined in the relation. Returns the initialized object if validation fails.
Expects arguments in the same format as Base.create.
Examples
users = User.where(name: 'Oscar')
users.create # #<User id: 3, name: "oscar", ...>
users.create(name: 'fxn')
users.create # #<User id: 4, name: "fxn", ...>
users.create { |user| user.name = 'tenderlove' }
# #<User id: 5, name: "tenderlove", ...>
users.create(name: nil) # validation on name
# #<User id: nil, name: nil, ...>
Parameters
-
argsrest -
blockblock
Source
# File activerecord/lib/active_record/relation.rb, line 141
def create(*args, &block)
scoping { @klass.create(*args, &block) }
end
Defined in activerecord/lib/active_record/relation.rb line 141
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Relation