Using Web Socket for Real Time Push Notifications in Rails
Getting started with websocket in rails pretty simple and quick.
- Add
Gemfile
gem to your Gemfile and run the bundle command. - Run generator:
rails g websocket_rails:install
. - In your
application.js
do
application.js
1 2 3 4 5 |
|
- In
controller
from where ever the notification has to be sent
1 2 3 4 5 6 7 8 9 10 |
|
This is it, the minimal setup for using websocket is complete. Every time a task is created, a messages is sent to all over the active websocket connections. I have done console.log
. After getting data we can process it any ways we want. Such as :
1 2 3 4 |
|