开发者

How can I remove callbacks inserted by vendor code?

开发者 https://www.devze.com 2023-01-07 05:18 出处:网络
A gem I am using inserts an after_save callback that I would like to remove. It seems to me it w开发者_JS百科ould be cleaner to delete a symbol from an array than to fix the problem with a monkeypatch

A gem I am using inserts an after_save callback that I would like to remove. It seems to me it w开发者_JS百科ould 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?


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


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}
0

精彩评论

暂无评论...
验证码 换一张
取 消