cuando el arduino ya está creado no se guardan los sensores
This commit is contained in:
parent
3ac7755ab6
commit
d147a8ad9e
1 changed files with 5 additions and 3 deletions
|
@ -21,14 +21,14 @@ class ReadingsController < ActionController::API
|
|||
params[:arduinos]&.reject do |a|
|
||||
a[:id].blank? || a[:sensores].empty?
|
||||
end&.each do |a|
|
||||
arduino = raspberry.arduinos.find_or_initialize_by(local_id: a[:id])
|
||||
arduino = raspberry.arduinos.find_or_create_by(local_id: a[:id])
|
||||
|
||||
a[:sensores].each do |s|
|
||||
arduino.sensors.build(reading: reading, **sensor_params(s))
|
||||
arduino.sensors.create(reading: reading, **sensor_params(s))
|
||||
end
|
||||
end
|
||||
|
||||
if raspberry.save
|
||||
if raspberry.save!
|
||||
render plain: reading.id, status: :ok
|
||||
else
|
||||
head :bad_request
|
||||
|
@ -36,6 +36,8 @@ class ReadingsController < ActionController::API
|
|||
end
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
render plain: params[:transaction_uuid], status: :ok
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
head :bad_request
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in a new issue