Skip to main content

How do I subscribe action cable receiver to a new stream without resetting the entire channel subscription?

General • Asked by Himanshu G.

I have an inbuilt chat service on my application. A signed in user will select another user to start a conversation with them. How can I send stream for this new conversation to the 2 users without making them refetch subscriptions?
The only way it works as of now is re-subscribing to the conversations channel (refreshing the page emulates this).

def subscribed 
 conversations = current_user.conversations
 conversations.each do |conversation|
  stream_from "conversations:#{conversation.id}"
 end
end

This is the subscribed function I have. Whenever a user creates a new conversation current_user.conversations will change but to stream from the new conversation the subscription needs to be reset. Any ideas on a workaround ?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.