跳至内容 跳至搜索

当记录验证失败或由于任何 before_* 回调抛出 :abort 而无法保存时,由 ActiveRecord::Base#save!ActiveRecord::Base.update_attribute! 方法引发。有关详细信息,请参阅 ActiveRecord::Callbacks

class Product < ActiveRecord::Base
  before_save do
    throw :abort if price < 0
  end
end

Product.create! # => raises an ActiveRecord::RecordNotSaved
方法
N

属性

[R] record

类公共方法

new(message = nil, record = nil)

# File activerecord/lib/active_record/errors.rb, line 164
def initialize(message = nil, record = nil)
  @record = record
  super(message)
end