質問編集履歴
2
タグ変更しました
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
1
返信いただいた点について追記しました。ご確認よろしくおねがいいたします。
title
CHANGED
File without changes
|
body
CHANGED
@@ -120,4 +120,76 @@
|
|
120
120
|
|
121
121
|
```
|
122
122
|
|
123
|
-
ご確認よろしくおねがいいたします。
|
123
|
+
ご確認よろしくおねがいいたします。
|
124
|
+
|
125
|
+
|
126
|
+
######追記です
|
127
|
+
チャットルームにあるテキストフォームから投稿しようとした際に上記のエラーメッセージが出ます。
|
128
|
+
view.html.erbも追記しておきます
|
129
|
+
|
130
|
+
######app/models/message.rb
|
131
|
+
```
|
132
|
+
class Message < ApplicationRecord
|
133
|
+
after_create_commit { MessageBroadcastJob.perform_later self }
|
134
|
+
belongs_to :user
|
135
|
+
belongs_to :room
|
136
|
+
end
|
137
|
+
|
138
|
+
```
|
139
|
+
|
140
|
+
######db/schema.rbから抜粋
|
141
|
+
```
|
142
|
+
create_table "messages", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
143
|
+
t.text "content"
|
144
|
+
t.datetime "created_at", null: false
|
145
|
+
t.datetime "updated_at", null: false
|
146
|
+
t.bigint "user_id", null: false
|
147
|
+
t.bigint "room_id", null: false
|
148
|
+
t.index ["room_id"], name: "index_messages_on_room_id"
|
149
|
+
t.index ["user_id"], name: "index_messages_on_user_id"
|
150
|
+
end
|
151
|
+
|
152
|
+
create_table "rooms", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
153
|
+
t.datetime "created_at", null: false
|
154
|
+
t.datetime "updated_at", null: false
|
155
|
+
end
|
156
|
+
|
157
|
+
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
158
|
+
t.string "email", default: "", null: false
|
159
|
+
t.string "encrypted_password", default: "", null: false
|
160
|
+
t.string "reset_password_token"
|
161
|
+
t.datetime "reset_password_sent_at"
|
162
|
+
t.datetime "remember_created_at"
|
163
|
+
t.datetime "created_at", null: false
|
164
|
+
t.datetime "updated_at", null: false
|
165
|
+
t.string "name", default: "", null: false
|
166
|
+
t.text "profile"
|
167
|
+
t.string "thumb"
|
168
|
+
t.string "image"
|
169
|
+
t.boolean "admin", default: false
|
170
|
+
t.index ["email"], name: "index_users_on_email", unique: true
|
171
|
+
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
172
|
+
end
|
173
|
+
|
174
|
+
add_foreign_key "messages", "rooms"
|
175
|
+
add_foreign_key "messages", "users"
|
176
|
+
|
177
|
+
```
|
178
|
+
######app/views/rooms/show.html.erb
|
179
|
+
```
|
180
|
+
<h1>Chat room</h1>
|
181
|
+
|
182
|
+
<div id='messages' data-room_id="<%= @room.id %>">
|
183
|
+
<%= render @messages %>
|
184
|
+
</div>
|
185
|
+
<form>
|
186
|
+
<label>Say something:</label><br>
|
187
|
+
<input type="text" data-behavior="room_speaker">
|
188
|
+
</form>
|
189
|
+
```
|
190
|
+
######app/views/messages/_message.html.erb
|
191
|
+
```
|
192
|
+
<div class="message">
|
193
|
+
<p><%= "#{message.user.email}" %>:<%= time_ago_in_words(message.created_at)+"前" %>:<%= message.content %></p>
|
194
|
+
</div>
|
195
|
+
```
|