Topic: after_initialize not being called

Just updated rails from 3.0 to latest 3.2.8 and did the ruby switch to 1.9.3.

I updated my application got the kinks ironed out that I ran into.  However, now my after_initialize defined as a method in my models that inherit from ActiveRecord::Base are not being run when I either do a find or new.

I am clueless as to why this is happening and have read a ton of documentation, posts, scrolled through numerous searches, etc.

Anyone have anything I can try or willing to give me a lightbulb moment?

FYI, I did try to define after_find() and print a test string.  No joy.

sticks

Re: after_initialize not being called

I've never used the after_initialize call back before but I just tried it on a new test app like so

class PlayTime < ActiveRecord::Base
  after_initialize :log_output

  private
    def log_output
      logger.debug("@@@@ - After initialize called")
    end
end

And I got the expected output in my log file

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: after_initialize not being called

Thanks for the quick reply.  You set me on the right path.  My old code worked and looked similar to the following:

def after_initialize
  @state=1
  puts "test string"
end

So evidently that used to be fine, but now you have to call it as you did.  I just renamed my after_initialize block to setup and added

after_initialize :setup

Seems like a long way around, but it works.  Thanks for stopping me from beating my head against the wall further.