diff --git a/controllers/custom_wizard/realtime_validations.rb b/controllers/custom_wizard/realtime_validations.rb index 38ae1a0d..00b8c686 100644 --- a/controllers/custom_wizard/realtime_validations.rb +++ b/controllers/custom_wizard/realtime_validations.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + class CustomWizard::RealtimeValidationsController < ::ApplicationController def validate params.require(:validation) params.require(::CustomWizard::RealtimeValidation.types[params[:validation].to_sym][:required_params]) - render_json_dump(::CustomWizard::RealtimeValidation.send(params[:validation], params, current_user)) + result = ::CustomWizard::RealtimeValidation.send(params[:validation], params, current_user) + render_serialized(result[:items], result[:serializer], result[:opts]) end end diff --git a/lib/custom_wizard/realtime_validation.rb b/lib/custom_wizard/realtime_validation.rb index 2dcaa50b..055965f6 100644 --- a/lib/custom_wizard/realtime_validation.rb +++ b/lib/custom_wizard/realtime_validation.rb @@ -32,6 +32,6 @@ class CustomWizard::RealtimeValidation topics.select! { |t| categories.include?(t.category.id.to_s) } if categories.present? topics.select! { |t| t.created_at > DateTime.parse(date_after) } if date_after.present? topics.map! { |t| SimilarTopic.new(t) } - ::ActiveModel::ArraySerializer.new(topics, each_serializer: SimilarTopicSerializer, root: :similar_topics, rest_serializer: true, scope: ::Guardian.new(current_user)) + { items: topics, serializer: SimilarTopicSerializer, opts: { root: :similar_topics } } end end