title: Rails Activerecord observer not working
body: <p>In rails 3.1 app,
  I am trying to create an observable activerecord observer, but seems it doesn't work.<br/>
  Even  creating only activerecord observer without being observable, the after_create 
  event is not called, the string "in after create event" is never printed out.
  The caller is a rake task.</p>
  
  <p>Here's the code sample to make it clear.</p>
  
  <pre><code>class PostTemp &lt; ActiveRecord::Base  
  
  end
  
  
  class PostTempObserver &lt; ActiveRecord::Observer
    include Observable
    attr_reader :new_data
  
    def initialize
      @new_data = 0
    end
  
    def after_create(record)
      #binding.pry
      puts "in after create event"
      @new_data = 1
      notify_observers(@new_data)
      @new_data = 0
    end
  
    def reset_new_data
      @new_data = 0
    end
  
  end
  
  
  class Notifier  
    attr_reader :total_new_data
  
    def initialize(model_observer)
      model_observer.add_observer(self)
      @total_new_data = 0
    end
  
    def update(new_data_flag)
      @total_new_data = @total_new_data + new_data_flag
    end
  
    def perform
      if @total_new_data &gt; 0
        #send notification
        puts "notify to  bar app..."    
        @total_new_data = 0
      else
        puts "no new data"  
      end
  
    end
  
  end
  
  #in config/application.rb
  config.active_record.observers = :post_temp_observer
  </code></pre>
  
  <p>in task1.rake</p>
  
  <pre><code>namespace :foo do
    desc "crawl message and notify if there's new data"
    task :get_message =&gt; :environment do
     post_temp_observer = PostTempObserver.instance
     notifier = Notifier.new(post_temp_observer)
      #..
      #do some crawling
      #..
  
    notifier.perform
  
    end
  
  end
  </code></pre>