Created
January 3, 2013 05:42
-
-
Save emarthinsen/4441100 to your computer and use it in GitHub Desktop.
Trying to get some custom AR callbacks to trigger corresponding handlers in an observer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DashboardObserver < ActiveRecord::Observer | |
observe :user | |
def after_activate(user) | |
DashboardService.update_metrics | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
include User::Authentication | |
define_model_callbacks :upgrade, :downgrade, :cancel, :activate, :deactivate | |
#large swaths of code | |
def activate! | |
run_callbacks :activate do | |
self.update_attribute(:active, true) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, I'm trying to create a custom callback in User. When a user is activated, I want the 'activate' callback to fire and to be handled in my DashboardObserver. As the code stands, the observer never sees the callback get raised.
Note, I'm using the define_model_callbacks method above. I get the same results if I use define_model.
And, yes, I've correctly registered the observer in application.rb