[Rails] Adding children via small subform

Doug Bromley
2006-02-08T23:15:51Z

I''ve read AWDR and especially the part concerning adding child
line_items to an order.  Unfortunately I want to do my process in
reverse and in doing what I thought would work I get a null object error
when trying to append the children to the parent.

This is a _major_ stumbling block in my Rails use as almost every one of
my projects has needed this so its a pretty vital problem I need to
overcome.

My two tables:
Reviews -< Pictures
(Parent) -< (Child)

I have a form where you first add a Review and after clicking an Ajax
link it produces a sub-form ready for inputting the child pictures.
However, no matter whether I want just one child or a group of children
on the form I can''t seem to get the Child objects to
''<<'' (append) to
the parent object.

In the book you collect your cart of ''children'' (line_items)
then append
these after creating an order.

My code is (in this instance I try it with just a single child):
@picture = Picture.new(params[:picture])
@review = Review.new(params[:review])
@review.pictures << @picture.pictures

I''m totally at a loss and I''m on hands and knees.  Please
please help
me.  I want to go far with Rails and this is killing me.

Thank you for reading.

--
Posted via http://www.ruby-forum.com/.