mercredi 11 mars 2015

how can I use ActiveRecord Create for multiple records Ruby on Rails?

I have a ruby method that returns multiple records with 7 columns. I want to insert these records to the other table which has more than 15 columns.


How can I use the ActiveRecord Create method in my model to insert those records to match exactly into the new table which has the same column name.


Ex:


I have a model method like the following:



def self.record_letter_group
.....
end


In the console, when i try to run this method, it returns the following records



([#<Letter::Group User_ID: "sri", Code: "12345", Group_ID: 15>,
#<Letter::Group User_ID: "sri", Code: "12445", Group_ID: 15>,
#<Letter::Group User_ID: "sri", Code: "12545", Group_ID: 15>,
#<Letter::Group User_ID: "sri", Code: "12645", Group_ID: 15>,
#<Letter::Group User_ID: "sri", Code: "12745", Group_ID: 15>,
])


I want to do something like,



save_records = Letter::Category.create(record_letter_group)


Note: This Letter::Category has 15 columns


Thanks


Aucun commentaire:

Enregistrer un commentaire