Add missing safe navigation operator

Add missing safe navigation operator
From fb784142298ea3f9a5c2d1da4863aca2ef167f0e Mon Sep 17 00:00:00 2001
From: Vinoth Kannan <vinothkannan@vinkas.com>
Date: Wed, 5 Dec 2018 16:23:43 +0530
Subject: [PATCH] Add missing safe navigation operator


diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb
index b72a3b7..dc8a21d 100644
--- a/app/models/web_hook.rb
+++ b/app/models/web_hook.rb
@@ -73,7 +73,7 @@ class WebHook < ActiveRecord::Base
       WebHook.enqueue_hooks(:topic, event,
         id: topic.id,
         category_id: topic&.category_id,
-        tag_ids: topic&.tags.pluck(:id),
+        tag_ids: topic&.tags&.pluck(:id),
         payload: payload
       )
     end
@@ -86,7 +86,7 @@ class WebHook < ActiveRecord::Base
       WebHook.enqueue_hooks(:post, event,
         id: post.id,
         category_id: post&.topic&.category_id,
-        tag_ids: post&.topic&.tags.pluck(:id),
+        tag_ids: post&.topic&.tags&.pluck(:id),
         payload: payload
       )
     end

GitHub

Needs a bit more follow up, what is the use case of raising a hook when there is no topic ?

Like @gschlager mentioned here we don’t need safe navigation for topic. We already calling topic.id twice in code without any issues.

I did some improvements here.

1 Like