Merge pull request #1605 from vikhyat/fix-activerecord-associations-collectionproxy-serialization

Fix serialization of ActiveRecord::Associations::CollectionProxy in Rails 4
This commit is contained in:
Robin Ward 2013-11-04 07:16:52 -08:00
commit ae81d78ab9
1 changed files with 1 additions and 1 deletions

View File

@ -134,7 +134,7 @@ class ApplicationController < ActionController::Base
def serialize_data(obj, serializer, opts={})
# If it's an array, apply the serializer as an each_serializer to the elements
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
ActiveModel::ArraySerializer.new(obj, serializer_opts).as_json
else