How do you build a child with a has_many?


#1

hi,
i just read that you use model.build_whatever to save a child
object…but what do you call when you have many children?

reports has_many images…

when i have 2 or more file fields in a form, what do i use to save the
images to my report? when report has_one image, i just call
@model.build_image(params[:something]) but how about if report has_many
images?

thanks.


#2

On 2/25/07, mixplate removed_email_address@domain.invalid wrote:

images to my report? when report has_one image, i just call
@model.build_image(params[:something]) but how about if report has_many
images?

@report.images.build(params[:first_image])
@report.images.build(params[:second_image])

If you want to find out more about this, then see:
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000642