From 8eee4495b59467176b623260219417e8e31a057b Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 25 Oct 2016 12:47:55 +0800 Subject: [PATCH] handle policy_scope returning nil in application serializer --- app/serializers/api/v2/application_serializer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/serializers/api/v2/application_serializer.rb b/app/serializers/api/v2/application_serializer.rb index 35573fab..4345c941 100644 --- a/app/serializers/api/v2/application_serializer.rb +++ b/app/serializers/api/v2/application_serializer.rb @@ -32,10 +32,10 @@ module Api if attr.to_s.pluralize == attr.to_s attribute("#{attr.to_s.singularize}_ids".to_sym, opts.merge(unless: -> { embeds.include?(key) })) do - Pundit.policy_scope(scope[:current_user], object.send(attr)).map(&:id) + Pundit.policy_scope(scope[:current_user], object.send(attr))&.map(&:id) || [] end has_many(attr, opts.merge(if: -> { embeds.include?(key) })) do - Pundit.policy_scope(scope[:current_user], object.send(attr)) + Pundit.policy_scope(scope[:current_user], object.send(attr)) || [] end else id_opts = opts.merge(key: "#{key}_id")