refactor general settings controller to handle available_units params

This commit is contained in:
Andy Brett
2020-10-06 17:30:09 -07:00
parent 4f579facfe
commit c9b540677c

View File

@@ -10,13 +10,7 @@ module Spree
end
def update
available_units = []
params.each do |name, value|
if value == "1" && unit = name.match(/available_units_(.*)/)&.captures&.first
available_units << unit
end
end
Spree::Config[:available_units] = available_units.join(",")
combine_available_units_params
params.each do |name, value|
next unless Spree::Config.has_preference? name
@@ -26,6 +20,18 @@ module Spree
redirect_to spree.edit_admin_general_settings_path
end
private
def combine_available_units_params
available_units = []
params.each do |name, value|
if value == "1" && unit = name.match(/available_units_(.*)/)&.captures&.first
available_units << unit
end
end
params[:available_units] = available_units.join(",")
end
end
end
end