I am disappointed with myself that I can't find the answer to this, but I've spent the morning trying various things and am obviously missing something. I have a simple setup where a Plan has_many Years. What I want to do, upon creation of a new Plan, is to also set up a certain number of Year objects. Each Year will be initialized according to variables dependent on context, and the number of them will also vary depending on the situation. But as a rule, each Plan will start out life with more than one Year, so I'd like to do that right in the constructor and be done with it. What is the syntax for how I would access years inside of Plan? I found write_attribute(:foo, 'bar') for dealing with traditional attributes, but it didn't seem totally relevant to what I want to do here. I'm drawing a complete blank. Outside the actual Plan object, it works fine: a = Plan.new a.years << Year.new(:comment=>'works') a.years << Year.new(:comment=>'also works') I just want that to work inside the Plan constructor. What am I overlooking? Thanks!
on 2007-07-24 18:10