Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert observers not firing :(...

Replytotopic

observers not firing :(

Posted in Forums : Ask a Rails expert

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Hi experts!

I am a rails newbie struggling w/ this observer issue. I have an observer I want to use for audits.

I have this at the tail end of my environment.rb

AuditObserver.instance

puts “after instantiation #{AuditObserver.instance}”

AuditObserver.instance.observed_classes.each {|x| puts x.name }

All of these appear to work correctly. The right model classes are in the output.

However, my observer doesn’t fire at all. Every few runs I’ve seen it fire occasionally, but I am unable to find a pattern. Obviously this is not enough information, but I am not even sure how or what to look for. Any help or direction is appreciated. I am at a total loss.

Some highlights about the observer. It is observing multiple models and it is calling Audit.create (where Audit is another model object that stores the audit)

And one more thing. This started happening after I added the acts_as_soft_deletable plugin, which was the reason I added the AuditObserver.instance to the bottom of my environment.rb and didn’t use config.active_record.observers (which was working fine). I am on rails 2.0.2 w/ Ruby 1.8.3

Vijay

 
Me

Authority 62
Posting Rating 100
Sign in to rate this post

If it started happening after you’ve installed the plugin, I suggest you get in touch with the developer an ask him if this is a known issue. If not, you might have discovered a bug and he’ll be grateful to know.

 
Profile

Authority 0
Posting Rating 0
Sign in to rate this post

Thanks for the response Clemens. I would let the plugin developer know, except I am close to certain it’s not an issue with the plugin. I think it has to do with the Observer being initialized at the end of environment.rb vs. using config.active_record.observers.

 
Me

Authority 62
Posting Rating 100
Sign in to rate this post

I’m pretty sure it’s got nothing to do with where in the environment you put the observers call. All this configuration block does is set up a few variables in Rails that are used later in the game. Varying the order of options doesn’t change the functionality (at least it shouldn’t).

Replytotopic

Other Recent Topics

Ask a Rails expert : How to work with ror 2.1.1 using Netbeans IDE 6.1

Ask a Rails expert : json gem error

Ask a Rails expert : Problem with break

Ask a Rails expert : activesupport string first method error

Ask a Rails expert : url_for broken ?

Ask a Rails expert : map.routes.rb pls help

Ask a Rails expert : how to h tag in controller

Ask a Rails expert : Problem with Restful routing and partial form

Ask a Rails expert : will_paginate, search and ajax

Ask a Rails expert : captcha

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel