ActiveRecord Bang methods

suggest change

If you need an Active Record method to raise an exception instead of returning false or nil on failure, add ! to the method name. Some failures are easy to miss without it. During development, prefer these bang methods so invalid data raises immediately.

class User < ActiveRecord::Base
  validates :last_name, presence: true
end

User.create!(first_name: "John")
#=> ActiveRecord::RecordInvalid: Validation failed: Last name can't be blank

Active Record methods that accept a bang (!) include:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents