mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
refactor general settings controller to handle available_units params
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user