0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-29 12:20:27 +01:00
discourse-custom-wizard/controllers/custom_wizard/admin/custom_fields.rb
2020-10-20 16:40:23 +11:00

47 Zeilen
Kein EOL
958 B
Ruby

class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
def index
render_json_dump(custom_field_list)
end
def update
custom_fields = custom_field_params[:custom_fields].map do |data|
CustomWizard::CustomField.new(data.to_h)
end
custom_fields.each do |custom_field|
custom_field.validate
unless custom_field.valid?
raise Discourse::InvalidParameters,
custom_field.errors.full_messages.join("\n\n")
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 json: success_json
else
render json: error_json
end
end
private
def custom_field_params
params.permit(
custom_fields: [
:klass,
:name,
:type,
serializers: []
]
)
end
end