From 855ee3b43da817c2e1700818dd4d6bca92203412 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Sun, 3 Nov 2013 10:41:38 +0530 Subject: [PATCH] Fix ActiveRecord::Associations::CollectionProxy serialization in Rails 4. --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5a7dad77f09..2a339818d26 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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