Re: has one assciation insert record question

Frederick Cheung
Thu, 11 Jun 2009 09:17:41 -0000

On Jun 11, 9:53 am, Valentino Lun
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:

> I use the following ruby code to insert a new record, but I think it is
> not clever.
>
> a = Event.new
> a.cluster_code = "KWC"
> a.hosp_code = "CMC"
> a.save
> b = EventDetail.new
> b.id = a.id.to_i
> b.detail = "This is detail"

with associations you get a.build_event_detail for free. The
associations guide ( http://guides.rubyonrails.org/association_basics.html
) has more details


Fred
>
> Any one have a better solution? Please share.
>
> Many thanks
> Valentino
> --
> Posted viahttp://www.ruby-forum.com/.