views:

62

answers:

2

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?

+1  A: 

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}
Geoff Lanotte
Looks good… but where/when would I do that? Within the class definition?
John
I would say so, right with your other callbacks. As long as it is loaded after your plugin then it should be good to go.
Geoff Lanotte
If you're interested, here's the solution I ended up with for my particular problem: http://stackoverflow.com/questions/3162867/how-can-i-get-authlogic-to-use-the-rails-session-instead-of-its-own-cookie
John
+1  A: 
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
w1rele55
thanks-- this looks much better than my solution :-) i'm on a rails 2 project for now though, upgrading to rails 3 soon, i'll try it then.
John