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!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---