0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 01:10:28 +01:00

moved serialization logic to the controller

Dieser Commit ist enthalten in:
Faizaan Gagan 2021-02-15 18:12:32 +05:30
Ursprung 20c8d8493e
Commit 69ce09bdf7
2 geänderte Dateien mit 5 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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

Datei anzeigen

@ -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