Method: ActiveRecord::Associations::CollectionProxy#create!
- Defined in:
- activerecord/lib/active_record/associations/collection_proxy.rb
#create!(attributes = {}, &block) ⇒ Object
Like #create, except that if the record is invalid, raises an exception.
class Person
has_many :pets
end
class Pet
validates :name, presence: true
end
person.pets.create!(name: nil)
# => ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
365 366 367 |
# File 'activerecord/lib/active_record/associations/collection_proxy.rb', line 365 def create!(attributes = {}, &block) @association.create!(attributes, &block) end |