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
2010-07-13 20:27:28
Looks good… but where/when would I do that? Within the class definition?
John
2010-07-15 16:38:00
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
2010-07-15 17:06:46
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
2010-07-28 10:01:21
+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
2010-09-29 07:07:12
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
2010-10-22 04:12:58