質問編集履歴
3
d
test
CHANGED
File without changes
|
test
CHANGED
@@ -116,6 +116,68 @@
|
|
116
116
|
|
117
117
|
```
|
118
118
|
|
119
|
+
\app\channels\application_cable\channel.rb
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
|
123
|
+
module ApplicationCable
|
124
|
+
|
125
|
+
class Channel < ActionCable::Channel::Base
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
app\channels\application_cable\connection.rb
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
|
141
|
+
class Connection < ActionCable::Connection::Base
|
142
|
+
|
143
|
+
identified_by :current_user
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
def connect
|
148
|
+
|
149
|
+
self.current_user = find_verified_user
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
protected
|
156
|
+
|
157
|
+
def find_verified_user
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
if current_user = User.find_by(id: cookies.encrypted[:user_id])
|
162
|
+
|
163
|
+
current_user
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
reject_unauthorized_connection
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```
|
180
|
+
|
119
181
|
|
120
182
|
|
121
183
|
### 試したこと
|
2
あ
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,9 +66,9 @@
|
|
66
66
|
|
67
67
|
### 該当のソースコード
|
68
68
|
|
69
|
-
websocketが起動
|
69
|
+
rails5環境(websocketが起動)では、rails s で
|
70
70
|
|
71
|
-
「
|
71
|
+
「ChatChannel subscribed」が出力されます。
|
72
72
|
|
73
73
|
|
74
74
|
|
1
あ
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,6 +66,10 @@
|
|
66
66
|
|
67
67
|
### 該当のソースコード
|
68
68
|
|
69
|
+
websocketが起動していれば、rails s で
|
70
|
+
|
71
|
+
「"ChatChannel subscribed"」が出力されます。
|
72
|
+
|
69
73
|
|
70
74
|
|
71
75
|
\app\channels\chat_channel.rb
|