質問編集履歴
2
タグ変更しました
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
1
返信いただいた点について追記しました。ご確認よろしくおねがいいたします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -243,3 +243,147 @@
|
|
243
243
|
|
244
244
|
|
245
245
|
ご確認よろしくおねがいいたします。
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
######追記です
|
252
|
+
|
253
|
+
チャットルームにあるテキストフォームから投稿しようとした際に上記のエラーメッセージが出ます。
|
254
|
+
|
255
|
+
view.html.erbも追記しておきます
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
######app/models/message.rb
|
260
|
+
|
261
|
+
```
|
262
|
+
|
263
|
+
class Message < ApplicationRecord
|
264
|
+
|
265
|
+
after_create_commit { MessageBroadcastJob.perform_later self }
|
266
|
+
|
267
|
+
belongs_to :user
|
268
|
+
|
269
|
+
belongs_to :room
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
######db/schema.rbから抜粋
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
create_table "messages", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
284
|
+
|
285
|
+
t.text "content"
|
286
|
+
|
287
|
+
t.datetime "created_at", null: false
|
288
|
+
|
289
|
+
t.datetime "updated_at", null: false
|
290
|
+
|
291
|
+
t.bigint "user_id", null: false
|
292
|
+
|
293
|
+
t.bigint "room_id", null: false
|
294
|
+
|
295
|
+
t.index ["room_id"], name: "index_messages_on_room_id"
|
296
|
+
|
297
|
+
t.index ["user_id"], name: "index_messages_on_user_id"
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
create_table "rooms", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
304
|
+
|
305
|
+
t.datetime "created_at", null: false
|
306
|
+
|
307
|
+
t.datetime "updated_at", null: false
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
314
|
+
|
315
|
+
t.string "email", default: "", null: false
|
316
|
+
|
317
|
+
t.string "encrypted_password", default: "", null: false
|
318
|
+
|
319
|
+
t.string "reset_password_token"
|
320
|
+
|
321
|
+
t.datetime "reset_password_sent_at"
|
322
|
+
|
323
|
+
t.datetime "remember_created_at"
|
324
|
+
|
325
|
+
t.datetime "created_at", null: false
|
326
|
+
|
327
|
+
t.datetime "updated_at", null: false
|
328
|
+
|
329
|
+
t.string "name", default: "", null: false
|
330
|
+
|
331
|
+
t.text "profile"
|
332
|
+
|
333
|
+
t.string "thumb"
|
334
|
+
|
335
|
+
t.string "image"
|
336
|
+
|
337
|
+
t.boolean "admin", default: false
|
338
|
+
|
339
|
+
t.index ["email"], name: "index_users_on_email", unique: true
|
340
|
+
|
341
|
+
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
add_foreign_key "messages", "rooms"
|
348
|
+
|
349
|
+
add_foreign_key "messages", "users"
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
```
|
354
|
+
|
355
|
+
######app/views/rooms/show.html.erb
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
<h1>Chat room</h1>
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
<div id='messages' data-room_id="<%= @room.id %>">
|
364
|
+
|
365
|
+
<%= render @messages %>
|
366
|
+
|
367
|
+
</div>
|
368
|
+
|
369
|
+
<form>
|
370
|
+
|
371
|
+
<label>Say something:</label><br>
|
372
|
+
|
373
|
+
<input type="text" data-behavior="room_speaker">
|
374
|
+
|
375
|
+
</form>
|
376
|
+
|
377
|
+
```
|
378
|
+
|
379
|
+
######app/views/messages/_message.html.erb
|
380
|
+
|
381
|
+
```
|
382
|
+
|
383
|
+
<div class="message">
|
384
|
+
|
385
|
+
<p><%= "#{message.user.email}" %>:<%= time_ago_in_words(message.created_at)+"前" %>:<%= message.content %></p>
|
386
|
+
|
387
|
+
</div>
|
388
|
+
|
389
|
+
```
|