跳至内容 跳至搜索

当由于任何 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

Attributes

[R] record

类公共方法

new(message = nil, record = nil)

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