I've been developing a quiz web application with Rails 5 and ActionCable and everything was working fine, but suddenly my browser started showing 2 'cable' websocket connections (and the logs also confirm that messages are sent twice).
What I'm talking about is this:
This is wholly unintentional on my part, but even after restarting the server and my PC and searching my code I don't get where the second connection comes from.
This is my connection.rb
- standard for ActionCable:
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user
end
private
def find_verified_user
if verified_user = User.find_by(id: cookies.signed[:user_id])
verified_user
else
reject_unauthorized_connection
end
end
end
end
This is my routes.rb
:
Rails.application.routes.draw do
root to: redirect('teacher/home'), :role => "teacher", :page => "home"
mount ActionCable.server => '/cable'
end
And this is the issue I was solving when the second connection started to appear. ^^*
I'd be happy for any ideas of where to look or what to do! :)