Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
343e2647
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
343e2647
编写于
4月 05, 2016
作者:
P
Prathamesh Sonpatki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ci skip] Fix formatting of code snippet in Action Cable guide
上级
c89e6926
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
7 deletion
+8
-7
guides/source/action_cable_overview.md
guides/source/action_cable_overview.md
+8
-7
未找到文件。
guides/source/action_cable_overview.md
浏览文件 @
343e2647
...
...
@@ -39,7 +39,7 @@ client-server connection instance established per WebSocket connection.
Connections form the foundation of the client-server relationship. For every WebSocket
the cable server is accepting, a Connection object will be instantiated on the server side.
This instance becomes the parent of all the channel subscriptions that are created from there on.
This instance becomes the parent of all the channel subscriptions that are created from there on.
The Connection itself does not deal with any specific application logic beyond authentication
and authorization. The client of a WebSocket connection is called a consumer. An individual
user will create one consumer-connection pair per browser tab, window, or device they have open.
...
...
@@ -73,12 +73,12 @@ end
```
Here
`identified_by`
is a connection identifier that can be used to find the
specific connection later. Note that anything marked as an identifier will automatically
specific connection later. Note that anything marked as an identifier will automatically
create a delegate by the same name on any channel instances created off the connection.
This example relies on the fact that you will already have handled authentication of the user
somewhere else in your application, and that a successful authentication sets a signed
cookie with the
`user_id`
.
somewhere else in your application, and that a successful authentication sets a signed
cookie with the
`user_id`
.
The cookie is then automatically sent to the connection instance when a new connection
is attempted, and you use that to set the
`current_user`
. By identifying the connection
...
...
@@ -89,8 +89,8 @@ or deauthorized).
### Channels
A channel encapsulates a logical unit of work, similar to what a controller does in a
regular MVC setup. By default, Rails creates a parent
`ApplicationCable::Channel`
class
for encapsulating shared logic between your channels.
regular MVC setup. By default, Rails creates a parent
`ApplicationCable::Channel`
class
for encapsulating shared logic between your channels.
#### Parent Channel Setup
...
...
@@ -150,7 +150,7 @@ established using the following Javascript, which is generated by default in Rai
App
.
cable
=
ActionCable
.
createConsumer
()
```
This will ready a consumer that'll connect against /cable on your server by default.
This will ready a consumer that'll connect against /cable on your server by default.
The connection won't be established until you've also specified at least one subscription
you're interested in having.
...
...
@@ -215,6 +215,7 @@ If a consumer is not streaming (subscribed to a given channel), they'll not
get the broadcast should they connect later.
Broadcasts are called elsewhere in your Rails application:
```
ruby
WebNotificationsChannel
.
broadcast_to
current_user
,
title:
'New things!'
,
body:
'All the news fit to print'
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录