[英]skip callback in inherited model
Is there a method like ActionController::Base#skip_before_filter
for ActiveRecord callbacks like after_create
? 对于像
after_create
ActionController::Base#skip_before_filter
的ActiveRecord回调,是否有类似ActionController::Base#skip_before_filter
的方法? I have a few classes that behave similarly, and to reduce code repetition I created an abstract class. 我有一些行为类似的类,为了减少代码重复,我创建了一个抽象类。 The abstraction contains relation information, validation and an
after_create
callback that creates a new message. 抽象包含关系信息,验证和创建
after_create
回调。 Message
implements this abstractions, so saving the message causes an stack overflow. Message
实现了这种抽象,因此保存消息会导致堆栈溢出。
Can I remove a callback from a model? 我可以从模型中删除回调吗?
class Parent < ActiveRecord::Base
self.abstract_class = true
after_create :notify
def notify
Message.create
end
end
class Message < Parent
# skip after_create :notify
end
class Child < Parent
end
class Message < Parent
skip_callback :create, :after, :notify
end
Check Rails Documentation for details 检查Rails文档以获取详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.