Fix issue with each_serializer not being called in some cases in Rails 4.

This commit is contained in:
Matt-Yorkley
2020-01-12 12:47:26 +01:00
parent 6bb4f2477c
commit 57ca1d54bb

View File

@@ -1,3 +1,4 @@
# rubocop:disable Metrics/ClassLength
module Spree
module Admin
class BaseController < Spree::BaseController
@@ -121,13 +122,17 @@ module Spree
def render_as_json(data, options = {})
ams_prefix = options.delete :ams_prefix
if [Array, ActiveRecord::Relation].include? data.class
if each_serializer_required?(data)
render options.merge(json: data, each_serializer: serializer(ams_prefix))
else
render options.merge(json: data, serializer: serializer(ams_prefix))
end
end
def each_serializer_required?(data)
['Array', 'ActiveRecord::Relation'].include?(data.class.name)
end
def serializer(ams_prefix)
unless ams_prefix.nil? || ams_prefix_whitelist.include?(ams_prefix.to_sym)
raise "Suffix '#{ams_prefix}' not found in ams_prefix_whitelist for #{self.class.name}."
@@ -140,3 +145,4 @@ module Spree
end
end
end
# rubocop:enable Metrics/ClassLength