Forum: Ruby on Rails how do you build a child with a has_many?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
mixplate (Guest)
on 2007-02-26 05:22
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.
Luke I. (Guest)
on 2007-02-26 18:25
(Received via mailing list)
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/As...
This topic is locked and can not be replied to.