How can I remove callbacks inserted by vendor code

2019-05-10 22:55发布

A gem I am using inserts an after_save callback that I would like to remove. It seems to me it would be cleaner to delete a symbol from an array than to fix the problem with a monkeypatch. How can I access the array of callbacks?

2条回答
再贱就再见
2楼-- · 2019-05-10 23:09
class UserSession < Authlogic::Session::Base
  # Don't use cookie AuthLogic behaviour
  skip_callback :persist, :persist_by_cookie
  skip_callback :after_save, :save_cookie
  skip_callback :after_destroy, :destroy_cookie
end
查看更多
劳资没心,怎么记你
3楼-- · 2019-05-10 23:09

the after_save array is accessible via Model.after_save, it is an array of ActiveSupport::Callbacks::Callback objects. You could run this from within the model

self.after_save.delete_if{|callback| callback.method == :do_something_callback}
查看更多
登录 后发表回答