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
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to