Save an array of models in rails -
i have array keeps instances of model (supplierphone) 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: "98776234423", created_at: "2011-07-21 00:56:27", updated_at: "2011-07-21 00:56:27">]
i want save each element of array supplier_phone in new instance of supplierphone, can tell me how can this?
thanks in advance!
supplier_phone.each{ |sp| suplierphone.create(sp.attributes) }
Comments
Post a Comment