컨트롤러 2개 조절

This commit is contained in:
2025-04-23 10:58:50 +09:00
parent 9291a5d1db
commit 2434c5b7aa
16 changed files with 106 additions and 100 deletions

View File

@@ -1,6 +1,6 @@
class ModalsController < ApplicationController
def open
@schedule = Schedule.new
render partial: "partials/modals_open", locals: { type: params[:type], close_button: params[:close_button] }
render partial: "partials/modals_open", locals: { type: params[:type], id: params[:id], close_button: params[:close_button] }
end
end

View File

@@ -1,11 +1,2 @@
class ModbusController < ApplicationController
def start
Modbus::PollingService.start
redirect_to schedules_path
end
def stop
Modbus::PollingService.stop
redirect_to schedules_path
end
end

View File

@@ -1,6 +1,11 @@
class SchedulesController < ApplicationController
def index
@schedule = Schedule.order(:hour, :minute)
@controllers = Controller.all
end
def view
@controller = Controller.find(params[:id])
@schedule = Schedule.where(controller_id: params[:id]).order(:hour, :minute)
@modbus_running = Modbus::PollingService.running?
end
@@ -12,10 +17,10 @@ class SchedulesController < ApplicationController
@schedule = Schedule.new(schedule_params)
if @schedule.save
redirect_to schedule_edit_schedules_path, notice: "스케쥴이 추가 되었습니다."
redirect_to schedule_edit_schedule_path(@schedule.controller_id), notice: "스케쥴이 추가 되었습니다."
else
error_messages = @schedule.errors.full_messages.join(", ")
redirect_to schedule_edit_schedules_path, alert: "스케쥴 추가 실패: #{error_messages}"
redirect_to schedule_edit_schedule_path(@schedule.controller_id), alert: "스케쥴 추가 실패: #{error_messages}"
end
end
@@ -23,23 +28,23 @@ class SchedulesController < ApplicationController
@schedule = Schedule.find_by(id: params[:id])
if @schedule.destroy
redirect_to schedule_edit_schedules_path, notice: "스케줄이 삭제되었습니다."
redirect_to schedule_edit_schedule_path(@schedule.controller_id), notice: "스케줄이 삭제되었습니다."
else
error_messages = @schedule.errors.full_messages.join(", ")
redirect_to schedule_edit_schedules_path, alert: "스케쥴 삭제 실패: #{error_messages}"
redirect_to schedule_edit_schedule_path(@schedule.controller_id), alert: "스케쥴 삭제 실패: #{error_messages}"
end
end
def reset
Schedule.delete_all
Schedule.where(controller_id: params[:id]).destroy_all
ActiveRecord::Base.connection.execute("DELETE FROM sqlite_sequence WHERE name='schedules'")
Rails.application.load_seed
redirect_to schedules_path, notice: "스케줄이 초기화되었습니다."
redirect_to schedule_edit_schedule_path(params[:id]), notice: "스케줄이 초기화되었습니다."
end
def schedule_edit
@schedule = Schedule.order(:hour, :minute)
@controller = Controller.find(params[:id])
@schedule = Schedule.where(controller_id: params[:id]).order(:hour, :minute)
end
def schedule_edit_update
@@ -63,14 +68,14 @@ class SchedulesController < ApplicationController
end
if error_messages.any?
redirect_to schedules_path, alert: error_messages.join("<br>")
redirect_to schedule_edit_schedule_path(params[:controller_id]), alert: error_messages.join("<br>")
else
redirect_to schedules_path, notice: "스케줄이 성공적으로 업데이트되었습니다."
redirect_to schedule_edit_schedule_path(params[:controller_id]), notice: "스케줄이 성공적으로 업데이트되었습니다."
end
end
private
def schedule_params
params.require(:schedule).permit(:hour, :minute, :is_active, :temperature)
params.require(:schedule).permit(:controller_id, :hour, :minute, :is_active, :temperature)
end
end