Walter Lee Davis
2010-Nov-12 19:23 UTC
Can''t seem to observe the before_destroy or after_destroy events
Ruby 1.8.7, Rails 2.3.10. I have an Observer set to watch :roles and :ads. I''ve declared it in my environment.rb Within that, I have the following methods (just testing right now): class ApproveObserver < ActiveRecord::Observer observe :role, :ad def after_create(record) Rails.logger.info( record.inspect ) end def after_update(record) Rails.logger.info( record.inspect ) end def before_destroy(record) Rails.logger.info( record.inspect ) end end Both create and update are working fine, but destroy -- whether I try before or after -- doesn''t fire off anything. Is that to do with the fact that I''m looking at a destroyed object after the fact, or is there something else going on here? Thanks in advance, Walter -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2010-Nov-12 20:01 UTC
Re: Can''t seem to observe the before_destroy or after_destroy events
On Nov 12, 2010, at 2:23 PM, Walter Lee Davis wrote:> Ruby 1.8.7, Rails 2.3.10. > > I have an Observer set to watch :roles and :ads. I''ve declared it in > my environment.rb Within that, I have the following methods (just > testing right now): > > class ApproveObserver < ActiveRecord::Observer > observe :role, :ad > def after_create(record) > Rails.logger.info( record.inspect ) > end > def after_update(record) > Rails.logger.info( record.inspect ) > end > def before_destroy(record) > Rails.logger.info( record.inspect ) > end > end > > Both create and update are working fine, but destroy -- whether I > try before or after -- doesn''t fire off anything. Is that to do with > the fact that I''m looking at a destroyed object after the fact, or > is there something else going on here? >Dumb, dumb, dumb... My controller was calling delete, not destroy. Changed that and all is well, it all works. Walter -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.