Fix ActiveRecord::Associations::CollectionProxy serialization in Rails 4.
This commit is contained in:
parent
04aa1690e2
commit
855ee3b43d
|
@ -134,7 +134,7 @@ class ApplicationController < ActionController::Base
|
||||||
def serialize_data(obj, serializer, opts={})
|
def serialize_data(obj, serializer, opts={})
|
||||||
# If it's an array, apply the serializer as an each_serializer to the elements
|
# If it's an array, apply the serializer as an each_serializer to the elements
|
||||||
serializer_opts = {scope: guardian}.merge!(opts)
|
serializer_opts = {scope: guardian}.merge!(opts)
|
||||||
if obj.is_a?(Array)
|
if obj.is_a?(Array) or obj.is_a?(ActiveRecord::Associations::CollectionProxy)
|
||||||
serializer_opts[:each_serializer] = serializer
|
serializer_opts[:each_serializer] = serializer
|
||||||
ActiveModel::ArraySerializer.new(obj, serializer_opts).as_json
|
ActiveModel::ArraySerializer.new(obj, serializer_opts).as_json
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue