분 추가 (스케쥴 new 추가 필요)

This commit is contained in:
2025-04-18 15:54:19 +09:00
parent cd7620672f
commit eb3bc33509
10 changed files with 127 additions and 48 deletions

View File

@@ -4,6 +4,16 @@ class ModbusController < ApplicationController
@modbus_running = Modbus::PollingService.running?
end
def destroy
schedule = Schedule.find_by(id: params[:id])
if schedule.destroy
redirect_to schedule_edit_modbus_index_path, notice: "스케줄이 삭제되었습니다."
else
redirect_to schedule_edit_modbus_index_path, alert: "스케줄 삭제에 실패했습니다."
end
end
def start
Modbus::PollingService.start
redirect_to modbus_index_path
@@ -19,17 +29,23 @@ class ModbusController < ApplicationController
end
def schedule_edit_update
error_hours = []
error_time = []
params[:schedule].each do |id, attributes|
schedule = Schedule.find_by(id: id)
unless schedule.update(temperature: attributes[:temperature])
error_hours << "#{schedule.hour}시"
unless schedule.update(
hour: attributes[:hour],
minute: attributes[:minute],
is_active: attributes[:is_active],
temperature: attributes[:temperature]
)
error_time << "#{schedule.hour}시 #{schedule.minute}분"
end
end
if error_hours.any?
redirect_to modbus_index_path, alert: "#{error_hours.join(', ')}의 온도 업데이트에 실패하였습니다."
if error_time.any?
redirect_to modbus_index_path, alert: "#{error_time.join(', ')}의 온도 업데이트에 실패하였습니다."
else
redirect_to modbus_index_path, notice: "스케줄이 성공적으로 업데이트되었습니다."
end