Rails 5: Action Cable demo
Why Stack Overflow recommends it
Stack Overflow users link it as the canonical walkthrough for getting started with Action Cable and as the reference setup they compare their own channel and subscription problems against.
Recommended by 3 people across 3 different months, 2015 to 2023.
What it is
A 22-minute screencast by Rails creator David Heinemeier Hansson demonstrating Action Cable, the WebSocket framework in Rails 5, by building a simple chat application. It covers generating a channel, subscribing from JavaScript, and broadcasting messages to connected clients.
What people said
Recommends Luka Domitrovič · 2016-05 · Stack Overflow · on “Rails ActiveJob and SSE: How to Update Page When An API Call is Finished”
Action Cable in Rails 5 is just build for this type of features. [LINK] Action Cable brings web sockets to rails, which means persisted connection between client and server. You can perform actions from client (javascript/coffescript) and push json or even html partial updates back to the client.The best sense of how Action Cable works you will get from dhh tutorial [this video] Generate new channel with rails g channel and set a scope of broadcast def subscribed stream_from "subscription_#{current_user.id}" end In your case steps 1 and 2 stays the same. On the end of the step 3. I would add ActionCable.server.broadcast "subscription_#{current_user.id}", status: payment_status . Step 4. update st
Recommends Tall Paul · 2017-03 · Stack Overflow · on “How can I call a channel method in a rails controller?”
So you should not be subscribing the user to the channel in the controller on create. It should be based on when they visit the page. You should change where users are connected by adding in a js/coffe file to do this for you based on who is connected. A good example/tutorial for this when I was learn was this video here [this video] . What the video leaves out is how to connect to an individual conversation. So I struggled with it and found a way to grab the conversation id from the url, probably not the best way but it works. Hope this helps conversation_id = parseInt(document.URL.match(new RegExp("conversations/"+ "(.*)"))[1]) # gets the conversation id from the url of the page App.conversatio
Recommends Vishal · 2019-08 · Stack Overflow · on “Action Cable only sending welcome and ping message to client”
the flow is quite different in terms of action cable. watch this video [this video] . you are not suppose to write this functions of socket in html file.
Cites Drenmi · 2015-12 · Stack Overflow · on “uninitialized constant > ActionCable::Server::Configuration::ApplicationCable”
According to DHH's video tutorial [this video] from yesterday, there's an issue between Spring and an ActionCable dependency, so until the final release of Rails 5 you will need to recreate your project with the --skip-spring option.
Cites Pan · 2016-02 · Stack Overflow · on “Connecting to ActionCable from iOS app”
I have been stuck on this all day. I have the very simple ActionCable example app (the chat app) by David Heinemeier Hansson working correctly ( [this video] ). I am trying to hit the websocket connection with an iPhone app. I am able to receive pings when I connect to ws://localhost:3000/cable , but I'm not quite sure how to subscribe to channels from outside of a javascript context.
Cites Andrew Patterson · 2016-02 · Stack Overflow · on “ActionCable channel subscription failing when I run the server and query on the Chrome console”
I am creating a chat app using Rails 5.0.0.beta2 which includes ActionCable for WebSockets. When I start the Puma server and reload the page, I am trying to test and see if I made the connection correctly and whether I can get a subscription confirmation to return in the console. [this video] (please see from 7:36 - 8:36) I am seeing neither a meta tag, nor am I able to query for App in the Chrome console. Does anyone have a suggestion for what I can do to debug this problem?
Cites Laser · 2016-04 · Stack Overflow · on “How do you create multiple channels with Actioncable; how does one pass an in-document variable to the javascript and ruby channels and jobs?”
For example, in [this video] at 10:36 he mentions the ability to create multiple channels, but how would one actually accomplish this? According to Rails 5 ActionCable establish stream from URL parameters [LINK] a variable can be defined and passed as a parameter like: def subscribed stream_from "room_channel_#{params[:roomId]}" end But in the javascript file prior to passing the data here, how does one pass in the data from the page? The following example renders an error as presumably the cable is defined before the document is loaded. App.room = App.cable.subscriptions.create { channel: "RoomChannel", roomId: document.getElementById("message_text").getAttribute("data-room")} Then, if one does
Cites Sylar · 2016-04 · Stack Overflow · on “More than one params with Rails 5 Action Cable”
David has a great video on how to use Action Cable for Rails 5 [this video] , for me, I am using the beta 3 version on Rails 5. The question is, is Action Cable only for a chat app where there is only one parameter passed as data ? Could I pass more than one params to speak ? RoomChannel (coffee): App.room = App.cable.subscriptions.create "RoomChannel", connected: -> # Called when the subscription is ready for use on the server disconnected: -> # Called when the subscription has been terminated by the server received: (data) -> alert data['message'] # Called when there's incoming data on the websocket for this channel speak: (message) -> # Could I pass in more than one params? @perform 'speak', m
Cites Gustavo Rubio · 2016-04 · Stack Overflow · on “Approach to a Notifications system with Rails 4”
While that would work you would still have a problem: how to push those notifications to the user. What this means is that if I get notifications from the system yet I don't reload the page I won't notice until I do so which brings you to two different solutions, which have to do with the client side management of it really: Polling [LINK] Something around WebSockets [LINK] Polling In case you decide to go with the option number 1 you would need to add client-side JavaScript code that keeps polling one endpoint of your application to check for the current user notifications so you can update the UI. Pros: You have a great control over the client side code and this can be implemented in almos
Cites Sylar · 2016-06 · Stack Overflow · on “Securing ActionCable in Rails 5”
I have played David's video [this video] repeatedly about ActionCable and still not see a way around this: to prevent someone from broadcasting a message from a browser's console. class RoomChannel < ApplicationCable::Channel ... # This is being called without any securities, or checking. def speak(data) end end Now from a the browser console, anyone can send a message and I do not want that: App.room.speak("I am God!"); Can someone please show me a complete guide for ActionCable? Is there a way to allow a certain user to a channel? What about the browser console? Am I missed something in David's video? My main concern is the sending of messages from the browser console as anyone can do that and