From 3b1f23806d10254d82b449875716306067e1ccf5 Mon Sep 17 00:00:00 2001 From: Zaid Huda Date: Mon, 15 Aug 2016 17:01:17 +0800 Subject: [PATCH] prevent multiple subscriptions to same channel on same page --- lib/private_pub/view_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private_pub/view_helpers.rb b/lib/private_pub/view_helpers.rb index 9048f36..d630f41 100644 --- a/lib/private_pub/view_helpers.rb +++ b/lib/private_pub/view_helpers.rb @@ -15,7 +15,11 @@ def publish_to(channel, data = nil, &block) def subscribe_to(channel) subscription = PrivatePub.subscription(:channel => channel) content_tag "script", :type => "text/javascript" do - raw("PrivatePub.sign(#{subscription.to_json});") + raw (" + if(PrivatePub.subscriptions['#{channel}'] === undefined){ + PrivatePub.sign(#{subscription.to_json}); + } + ") end end end