From 6a60d4559f1a06729b66f014c9a45eca13c636ca Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Mon, 28 Mar 2016 20:10:55 -0500 Subject: [PATCH] Handle render.ams with nil serializer or adapter --- lib/active_model/serializer.rb | 5 +++++ lib/active_model_serializers/logging.rb | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 79478abb7..80958d067 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -27,6 +27,11 @@ class Serializer include Links include Meta include Type + class Null < Serializer + def attributes; {}; end + def associations; {}; end + def serializable_hash; {}; end + end # @param resource [ActiveRecord::Base, ActiveModelSerializers::Model] # @return [ActiveModel::Serializer] diff --git a/lib/active_model_serializers/logging.rb b/lib/active_model_serializers/logging.rb index 2a859c413..c18797fbb 100644 --- a/lib/active_model_serializers/logging.rb +++ b/lib/active_model_serializers/logging.rb @@ -81,7 +81,10 @@ def notify_render(*) end def notify_render_payload - { serializer: serializer, adapter: adapter } + { + serializer: serializer || ActiveModel::Serializer::Null, + adapter: adapter || ActiveModelSerializers::Adapter::Null, + } end private