質問編集履歴
1
ソースコードの追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
RailsのActionCableを使った双方向の非同期通信でActiveStorageでUserに紐づいているアイコン画像を表示させたい
|
1
|
+
RailsのActionCableを使った双方向の非同期通信でActiveStorageでUserに紐づいているアイコン画像を表示させたい
|
test
CHANGED
@@ -166,7 +166,7 @@
|
|
166
166
|
|
167
167
|
```
|
168
168
|
|
169
|
-
```
|
169
|
+
```ruby
|
170
170
|
|
171
171
|
class MessagesController < ApplicationController
|
172
172
|
|
@@ -186,6 +186,76 @@
|
|
186
186
|
|
187
187
|
```
|
188
188
|
|
189
|
+
```ruby
|
190
|
+
|
191
|
+
class User < ApplicationRecord
|
192
|
+
|
193
|
+
# Include default devise modules. Others available are:
|
194
|
+
|
195
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
196
|
+
|
197
|
+
devise :database_authenticatable, :registerable,
|
198
|
+
|
199
|
+
:recoverable, :rememberable, :validatable
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
has_many :room_users
|
204
|
+
|
205
|
+
has_many :rooms, through: :room_users
|
206
|
+
|
207
|
+
has_many :messages
|
208
|
+
|
209
|
+
has_one_attached :icon
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
validates :name, presence: true
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
```html
|
220
|
+
|
221
|
+
<% @messages.each do |message| %>
|
222
|
+
|
223
|
+
<div id="message-container">
|
224
|
+
|
225
|
+
<%= render partial: 'message',locals: { message: message }%>
|
226
|
+
|
227
|
+
</div>
|
228
|
+
|
229
|
+
<% end %>
|
230
|
+
|
231
|
+
<div id="add-message">
|
232
|
+
|
233
|
+
</div>
|
234
|
+
|
235
|
+
</div>
|
236
|
+
|
237
|
+
</div>
|
238
|
+
|
239
|
+
<%= form_with model: [@room, @message], class:"message-form" do |f| %>
|
240
|
+
|
241
|
+
<%= f.text_field :content, class:"message-field", placeholder:"Message", autofocus: true %>
|
242
|
+
|
243
|
+
<label class="input-image">
|
244
|
+
|
245
|
+
<%= f.file_field :image, class: "upload-file" %>
|
246
|
+
|
247
|
+
</label>
|
248
|
+
|
249
|
+
<%= f.submit "", class:"send", id:"send" %>
|
250
|
+
|
251
|
+
<% end %>
|
252
|
+
|
253
|
+
</div>
|
254
|
+
|
255
|
+
</div>
|
256
|
+
|
257
|
+
```
|
258
|
+
|
189
259
|
|
190
260
|
|
191
261
|
### 試したこと
|
@@ -208,6 +278,8 @@
|
|
208
278
|
|
209
279
|
- ActionCable
|
210
280
|
|
281
|
+
- Devise
|
282
|
+
|
211
283
|
|
212
284
|
|
213
285
|
DB
|