Hello,-
does anyone have a good idea of how to trace a fault in the following:
I have a User model (user.rb) with these methods:
def create_reset_code code = User.get_random_string(10) #working class method self.password_reset_code = code self.save(false) @reset = true #Notifier.deliver_reset_notification(self) #works from here end
def recently_reset? @reset end
Also I have an Observer with this code:
class UserObserver < ActiveRecord::Observer def after_save(user) debugger puts "I observe " + user.username puts "Did " + user.username + " reset his password? " + user.recently_reset?.to_s Notifier.deliver_reset_notification(user) if user.recently_reset? end end
The problem is that the user.recently_reset? in the Observer returns nil.
When I test def recently_reset? interactively in the console (testing the User model), it works as intended. So the user model works correctly and the Observer does, too (as evidenced by the debugger and the first puts statement).
I tried to test the UserObserver interactively but get this:
obs = UserObserver.new
NoMethodError: private method `new' called for UserObserver:Class from (irb):1
Why does the Observer fail to read the user.recently_reset? correctly?
Thanks a lot, Vahagn