I’m trying to observe a User class, but I can’t get this to work, the
after_create method never gets called… (the breakpoint never gets
called)
app/models/user_observer.rb:
class UserObserver < ActiveRecord::Observer
def after_create(user)
breakpoint
setting = get_setting(‘sys_notify_enable_user_create’)
if setting? then
AdminMailer.deliver_simple_monitor_alert(‘Se ha creado
un nuevusuario’,
"Nombre: #{user.name} \nCorreo: #{user.email} \nDetalle:
#{user.detail} ")
end
end
end
UserObserver.instance
thats all i have and everything works as expected.
try removing the UserObserver.instance line at the end of your
observer definition and see what happens (restart webserver just to be
safe).
I don’t think specifying
observer User
in the observer class definition would do much as rails is supposed to
determine what to observe based on the class name of the observer. you
could try it though, and see what happens. wouldn’t hurt.
hmmm, i don’t remember if i did that or not. my guess is that it’s
there (can’t check because code is at work), i just didn’t check my
ApplicationController when i provided my settings.
I’ve removed UserObserver.instance and the observe User line too…
then
restarted webrick… and still not working… I’ve checked, and
rechecked
everithing and I can’t find what is wrong… finally I’ve put on
app/application.rb inside ApplicationController class the following:
observer :user_observer
and now everything is working…but I still don’t understand why this
doesn’t work as expected from enviroment.rb.
Thanks
Chris H.
escribió:
e my observer observes several models, I have to tell it