1
0
Fork 0
discourse-custom-wizard-unl.../controllers/custom_wizard/admin/custom_fields.rb
Angus McLeod d221d65d77 init
2020-10-17 12:31:07 +11:00

40 Zeilen
Kein EOL
894 B
Ruby

class CustomWizard::CustomFieldsController < CustomWizard::AdminController
def index
render_custom_field_list
end
def update
field_data = params[:custom_fields]
custom_fields = field_data.map { |data| CustomWizard::CustomFields.new(data) }
custom_fields.each do |field_data|
custom_field.validate
unless custom_field.valid?
raise Discourse::InvalidParameters, "Invalid field: '#{custom_field.name}'"
end
end
all_fields_saved = true
custom_fields.each do |field|
unless field.save
all_fields_saved = false
end
end
if all_fields_saved
render_custom_field_list
else
render json: error_json
end
end
def render_custom_field_list
render_serialized(
CustomWizard::CustomFields.list,
CustomWizard::CustomFieldsSerializer
)
end
end