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.
3eda6fcd3204ef285fa52176c28c4d3e?d=identicon&s=25 mixplate (Guest)
on 2007-02-26 04: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.
2017657725dd1bce83dc8a1e2e991d04?d=identicon&s=25 Luke Ivers (Guest)
on 2007-02-26 17:25
(Received via mailing list)
On 2/25/07, mixplate <rails-mailing-list@andreas-s.net> 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.