4

Is there a method like ActionController::Base#skip_before_filter for ActiveRecord callbacks like after_create? 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. Message implements this abstractions, so saving the message causes an stack overflow.

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
4

1 に答える 1

6
class Message < Parent
  skip_callback :create, :after, :notify
end

詳細については、 Rails のドキュメントを確認してください

于 2013-04-15T04:00:59.330 に答える