File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Rails Integration
2
+
3
+ This guide explains how to use ` async-websocket ` with ` falcon ` .
4
+
5
+ ## Project Setup
6
+
7
+ Firstly, we will create a new project for the purpose of this guide:
8
+
9
+ ~~~ bash
10
+ $ rails new websockets
11
+ --- snip ---
12
+ ~~~
13
+
14
+ Then, we need to add the [ Falcon] ( https://github.com/socketry/falcon ) web server and the ` Async::WebSocket ` gem:
15
+
16
+ ~~~ bash
17
+ $ bundle add falcon async-websocket
18
+ $ bundle remove puma
19
+ --- snip ---
20
+ $ rails s
21
+ => Booting Falcon
22
+ => Rails 6.0.3.1 application starting in development http://localhost:3000
23
+ => Run ` rails server --help` for more startup options
24
+ ~~~
25
+
26
+ ## Adding the WebSocket Controller
27
+
28
+ Firstly, generate the controller with a single method:
29
+
30
+ ~~~ bash
31
+ $ rails generate controller home index
32
+ ~~~
33
+
34
+ Then edit your controller implementation:
35
+
36
+ ~~~ ruby
37
+ require ' async/websocket/adapters/rack'
38
+
39
+ class HomeController < ApplicationController
40
+ def index
41
+ self .response = Async ::WebSocket ::Adapters ::Rack .open (request.env) do |connection |
42
+ connection.write({message: " Hello World" })
43
+ end
44
+ end
45
+ end
46
+ ~~~
47
+
48
+ ### Testing
49
+
50
+ You can quickly test that the above controller is working using a websocket client:
You can’t perform that action at this time.
0 commit comments