跳至内容 跳至搜索

当记录由于任何 before_destroy 回调抛出 :abort 而无法销毁时,由 ActiveRecord::Base#destroy! 抛出。有关更多详细信息,请参阅 ActiveRecord::Callbacks

class User < ActiveRecord::Base
  before_destroy do
    throw :abort if still_active?
  end
end

User.first.destroy! # => raises an ActiveRecord::RecordNotDestroyed
方法
N

属性

[R] record

类公共方法

new(message = nil, record = nil)

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