summaryrefslogtreecommitdiff
path: root/app/controllers/rafts_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/rafts_controller.rb')
-rw-r--r--app/controllers/rafts_controller.rb53
1 files changed, 14 insertions, 39 deletions
diff --git a/app/controllers/rafts_controller.rb b/app/controllers/rafts_controller.rb
index 96d99fd..c1c8a72 100644
--- a/app/controllers/rafts_controller.rb
+++ b/app/controllers/rafts_controller.rb
@@ -1,54 +1,29 @@
class RaftsController < ApplicationController
- before_action :set_collections, only: [ :editor ]
+ before_action :set_raft, only: %i[ edit update ]
+ before_action :set_crop, only: %i[ edit update ]
- def index
- redirect_to editor_rafts_path
+ def edit
end
- def editor
- # @beds, @crops set in before_action
- end
-
- # 1) Assign ALL rafts
- def assign_all
- crop_id = normalized_crop_id(params[:crop_id])
- Raft.update_all(crop_id: crop_id) # nil ok
- redirect_to editor_rafts_path, notice: "All rafts updated."
- end
-
- # 2) Assign all rafts in ONE bed
- def assign_bed
- bed = Bed.find(params.require(:bed_id))
- crop_id = normalized_crop_id(params[:crop_id])
- bed.rafts.update_all(crop_id: crop_id)
- redirect_to editor_rafts_path, notice: "Bed ##{bed.location} updated."
- end
-
- # 3) Assign ONE raft
- def assign_one
- raft = Raft.find(params[:id])
- val = params[:crop_id].to_s
-
- if val.blank? || val.casecmp("null").zero?
- # Skip validations; write NULL directly
- raft.update_column(:crop_id, nil)
+ def update
+ if @raft.update(raft_params)
+ redirect_to beds_path, notice: "Raft #{@raft.id} successfully updated."
else
- raft.update!(crop_id: val)
+ render :edit, status: :unprocessable_entity
end
-
- redirect_to editor_rafts_path(anchor: "bed-#{raft.bed_id}"), notice: "Raft updated."
end
private
- def set_collections
- @beds = Bed.order(:location)
+ def set_raft
+ @raft = Raft.find(params[:id])
+ end
+
+ def set_crop
@crops = Crop.order(:name)
end
- # Accept "", "null" → nil to allow clearing
- def normalized_crop_id(val)
- return nil if val.blank? || val.to_s.downcase == "null"
- val
+ def raft_params
+ params.require(:raft).permit(:location, :bed_id, :crop_id)
end
end
Copyright 2019--2025 Marius PETER