So what I am trying to do is run build on an object when it is first created (ex. User.new) then set some default values. First I was doing this in the controller:


u = User.new
u.address.build(zip => foo, :state => bar)


BUT

As I understand it though his is the type of thing that should go in the model. I thought I had a solution for this with:


def after_initialize
address.build(:zip => foo, :state => bar)
end


But after a while I started to notice problems. As it turns out after_initialize while seeming to only run after initializeing the model object also runs after a find as well. Obviously this caused problems. So I'm back on the hunt for a new solution.

As always I will post a solution if/when I find one.

Leave a Reply