From 18667712ea064d888175481d20aa816916b8e292 Mon Sep 17 00:00:00 2001 From: Wouter Willaert Date: Thu, 18 Sep 2014 18:23:39 +0200 Subject: [PATCH 1/2] Support both the `_render_option_json` and the newer `_render_with_renderer_json` methods --- lib/action_controller/serialization.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/action_controller/serialization.rb b/lib/action_controller/serialization.rb index 6a67275c..7b05084b 100644 --- a/lib/action_controller/serialization.rb +++ b/lib/action_controller/serialization.rb @@ -33,19 +33,22 @@ module ActionController end def serialization_scope - send(_serialization_scope) if _serialization_scope && respond_to?(_serialization_scope, true) + send(_serialization_scope) if _serialization_scope && + respond_to?(_serialization_scope, true) end def default_serializer_options end - def _render_option_json(resource, options) - json = ActiveModel::Serializer.build_json(self, resource, options) + %i(_render_option_json _render_with_renderer_json).each do |renderer_method| + define_method renderer_method do |resource, options| + json = ActiveModel::Serializer.build_json(self, resource, options) - if json - super(json, options) - else - super + if json + super(json, options) + else + super + end end end From 9ebd317898050c685ba332139e6b4935f1df5566 Mon Sep 17 00:00:00 2001 From: Wouter Willaert Date: Fri, 19 Sep 2014 10:55:23 +0200 Subject: [PATCH 2/2] Remove usage of %i --- lib/action_controller/serialization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/action_controller/serialization.rb b/lib/action_controller/serialization.rb index 7b05084b..75cd0804 100644 --- a/lib/action_controller/serialization.rb +++ b/lib/action_controller/serialization.rb @@ -40,7 +40,7 @@ module ActionController def default_serializer_options end - %i(_render_option_json _render_with_renderer_json).each do |renderer_method| + [:_render_option_json, :_render_with_renderer_json].each do |renderer_method| define_method renderer_method do |resource, options| json = ActiveModel::Serializer.build_json(self, resource, options)