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|
|
params[:arduinos]&.reject do |a|
|
||||||
a[:id].blank? || a[:sensores].empty?
|
a[:id].blank? || a[:sensores].empty?
|
||||||
end&.each do |a|
|
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|
|
a[:sensores].each do |s|
|
||||||
arduino.sensors.build(reading: reading, **sensor_params(s))
|
arduino.sensors.create(reading: reading, **sensor_params(s))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if raspberry.save
|
if raspberry.save!
|
||||||
render plain: reading.id, status: :ok
|
render plain: reading.id, status: :ok
|
||||||
else
|
else
|
||||||
head :bad_request
|
head :bad_request
|
||||||
|
@ -36,6 +36,8 @@ class ReadingsController < ActionController::API
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordNotUnique
|
rescue ActiveRecord::RecordNotUnique
|
||||||
render plain: params[:transaction_uuid], status: :ok
|
render plain: params[:transaction_uuid], status: :ok
|
||||||
|
rescue ActiveRecord::RecordInvalid
|
||||||
|
head :bad_request
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in a new issue