Considering your model Measurement has the next structure:
Measurement(
id: integer,
date: datetime,
location: string,
serial_number: integer,
humidity: float,
temperature: float,
created_at: datetime,
updated_at: datetime
)
You can easily iterate over your array of hashes and on each element, create a new Measurement record, like:
[
{ "date"=>"02/03/2017 11:46:11", "location"=>"Sissach", "serial_number"=>460631, "humidity"=>27.5, "temperature"=>17.4 },
{ "date"=>"02/03/2017 11:46:21", "location"=>"Sissach", "serial_number"=>460632, "humidity"=>27.2, "temperature"=>17.7 }
].each do |measurement|
Measurement.create(
location: measurement['location'],
serial_number: measurement['serial_number'],
date: measurement['date'],
humidity: measurement['humidity'],
temperature: measurement['temperature']
)
end
Or as @7urkm3n pointed out, just by passing the array of hashes it would work the same way.
Consider the block in case you need to do any extra operation, or if you want to initialize first a model object and then check if the record trying to be saved has success.
Measurement.create(array_here)