Skip to content

Commit 9761ff4

Browse files
committed
Rails documentation... wip.
1 parent 00500ef commit 9761ff4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

guides/rails-integration/readme.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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:

0 commit comments

Comments
 (0)