Thursday, June 2, 2016

Getting array of hashes from the API and saving it into a database | Fixed issues

Newest questions tagged ruby-on-rails - Stack Overflow

Getting array of hashes from the API and saving it into a database | Fixed issues


Getting array of hashes from the API and saving it into a database

Posted: 02 Jun 2016 07:01 AM PDT

how to save array of hashes into DB where each hash from the array would represent a db record? I am using JSONB. But I can't seem to iterate through array and save each separately. If for example I get array of 3 hashes from the API, I want my model to have 3 records: Model.count = 3 but it has 1 every time. Thanks.

controller:    data = get_data  cars = Car.new  # data.each do |d| (each doesn't do anything)    cars.data = data (here I get a lot of problems, depends if I am serializng data column as an Array or not)    cars.save  

No comments:

Post a Comment