Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 78ef7bf

Browse files
committed
moved helper function to equipment_models_controller.rb
1 parent 57b5263 commit 78ef7bf

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

app/controllers/application_controller.rb

-11
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,4 @@ def markdown_help
193193
end
194194
end
195195

196-
# function to check for deleted checkin/checkout procedures and hard-delete them after equipment model update
197-
def delete_procedures(params, phase)
198-
# phase needs to be equal to either "checkout" or "checkin"
199-
phase_params = params[:equipment_model][:"#{phase}_procedures_attributes"]
200-
phase_params.each do |k, v|
201-
if v["id"] and v["_destroy"] != "false"
202-
@equipment_model.send(:"#{phase}_procedures")[k.to_i].destroy(:force)
203-
end
204-
end
205-
end
206-
207196
end

app/controllers/equipment_models_controller.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def delete_files
6565

6666
def update
6767
delete_files
68-
68+
6969
if @equipment_model.update_attributes(params[:equipment_model])
7070
# hard-delete any deleted checkin/checkout procedures
7171
delete_procedures(params, "checkout")
@@ -82,4 +82,17 @@ def destroy
8282
flash[:notice] = "Successfully destroyed equipment model."
8383
redirect_to equipment_models_url
8484
end
85+
86+
private
87+
88+
# function to check for deleted checkin/checkout procedures and hard-delete them after equipment model update
89+
def delete_procedures(params, phase)
90+
# phase needs to be equal to either "checkout" or "checkin"
91+
phase_params = params[:equipment_model][:"#{phase}_procedures_attributes"]
92+
phase_params.each do |k, v|
93+
if v["id"] and v["_destroy"] != "false"
94+
@equipment_model.send(:"#{phase}_procedures")[k.to_i].destroy(:force)
95+
end
96+
end
97+
end
8598
end

0 commit comments

Comments
 (0)