Help please. 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 config/enviroment.rb: config.active_record.observers = :user_observer Thanks everybody
Take a peek at the acts_as_authenticated plugin, you should get plenty of inspiration from what they''ve done. http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated -z On 7/18/06, Matias <matiassurdi@gmail.com> wrote:> Help please. > > 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 > > > config/enviroment.rb: > config.active_record.observers = :user_observer > > > > > > Thanks everybody > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
you didn''t mention this, so i''ll ask. you changed environment.rb. so did you make sure to restart your webserver? Chris On 7/18/06, Matias <matiassurdi@gmail.com> wrote:> Help please. > > 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 > > > config/enviroment.rb: > config.active_record.observers = :user_observer > > > > > > Thanks everybody > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Yes.... I''ve done that already...... :-( Chris Hall escribi?:> you didn''t mention this, so i''ll ask. you changed environment.rb. so > did you make sure to restart your webserver? > > Chris > > On 7/18/06, Matias <matiassurdi@gmail.com> > wrote: >> Help please. >> >> 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 >> >> >> config/enviroment.rb: >> config.active_record.observers = :user_observer >> >> >> >> >> >> Thanks everybody >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >>
In my observer (which actually observers several models) file, I don''t have the UserObserver.instance line you have. and also, since my observer observes several models, I have to tell it which models to observe since it can''t infer from the observer name app/models/audit_observer.rb AuditObserver < ActiveRecord::Observer observer Order, Box, LineItem def after_create(model) model.log(...) end def after_update(model) model.log(...) end def after_destroy(model) model.log(...) end end # notice no AuditObserver.instance here then in environment.rb i have: config.active_record.observers = :audit_observer 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. hope this helps. Chris On 7/19/06, Matias <matiassurdi@gmail.com> wrote:> Yes.... I''ve done that already...... :-( > > Chris Hall escribi?: > > > you didn''t mention this, so i''ll ask. you changed environment.rb. so > > did you make sure to restart your webserver? > > > > Chris > > > > On 7/18/06, Matias <matiassurdi@gmail.com> > > wrote: > >> Help please. > >> > >> 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 > >> > >> > >> config/enviroment.rb: > >> config.active_record.observers = :user_observer > >> > >> > >> > >> > >> > >> Thanks everybody > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi, 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 Hall escribi?:> e my observer observes several models, I have to tell it
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. glad you got it working. Chris On 7/19/06, Matias <matiassurdi@gmail.com> wrote:> Hi, > > 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 Hall escribi?: > > > e my observer observes several models, I have to tell it > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks a lot for your help and your time Chris Hall escribi?:> 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. > > glad you got it working. > > Chris > > On 7/19/06, Matias <matiassurdi@gmail.com> > wrote: >> Hi, >> >> 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 Hall escribi?: >> >> > e my observer observes several models, I have to tell it >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >>