I have an array that keeps some instances of a model (SupplierPhone) like this:
supplier_phone = SupplierPhone.where(:supplier_id => 1)
supplier_phone = [#<SupplierPhone id: 1, supplier_id: 1, phone: "22423434234",
created_at: "2011-07-21 00:56:26", updated_at: "2011-07-21 00:56:26">,
#<SupplierPhone id: 2, supplier_id: 1, phone: "98开发者_开发问答776234423",
created_at: "2011-07-21 00:56:27", updated_at: "2011-07-21 00:56:27">]
I want to save each element of the array supplier_phone in a new instance of SupplierPhone, can somebody tell me how can I do this?
Thanks in advance!
supplier_phone.each{ |sp| SuplierPhone.create(sp.attributes) }
you can use associations. supplier has_many :phones", then get the phones through a chain "supplier.phones"
精彩评论