I have discovered ActionCable today and I have created a very simple chat. Now I want to add this into my current project.
When is a connection with a channel established? In my simple chat, I have a controller named Welcome with an index method and a channel named Demo. On the index page, you can write/see messages. I deduce when we access any page of the app, we are automatically connected to the channel? (if i don't add any instructions in connection.rb)
When you load the web page.
The client opens the connection to the actioncable channel. According to the docs in the client side section:
Followed by a subscription function such as:
That is what opens the connection to your channel which is defined (as in this example in the server side channels section): http://edgeguides.rubyonrails.org/action_cable_overview.html#channels
# app/channels/chat_channel.rb class ChatChannel < ApplicationCable::Channel # Called when the consumer has successfully # become a subscriber of this channel. def subscribed end end
subscribed method of your channel object.