質問編集履歴
4
更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
チャット機能を作成中です。エラー内容にcontentが定義されていないという趣旨の文とRelationとの記述からモデルかマイグレーションの定義に問題があるとみて、messagesのマイグレーションファイルにcontentsカラムがあるのか確かめたところ、カラム名がcontentではなくmessageになっていたのでcontentに変更しました。しかしながら、また同じエラー文が表示されてしまいました。他マイグレーションファイルかモデルファイルの定義が間違っているのでしょうか? ご指摘願います。
|
2
2
|
|
3
|
-
|
3
|
+
|
4
4
|
|
5
5
|
|
6
6
|
|
3
更新済
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[エラー]NoMethodError in RoomsPersonal#show undefined method `content' for #<ActiveRecord::Relation []
|
1
|
+
こ[エラー]NoMethodError in RoomsPersonal#show undefined method `content' for #<ActiveRecord::Relation []
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
![イメージ説明](01450f2e769314ec612d83a795102911.png)
|
12
12
|
|
13
13
|
|
14
14
|
|
2
更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
チャット機能を作成中です。エラー内容にcontentが定義されていないという趣旨の文とRelationとの記述からモデルかマイグレーションの定義に問題があるとみて、messagesのマイグレーションファイルにcontentsカラムがあるのか確かめたところ、カラム名がcontentではなくmessageになっていたのでcontentに変更しました。しかしながら、また同じエラー文が表示されてしまいました。他マイグレーションファイルかモデルファイルの定義が間違っているのでしょうか? ご指摘願います。
|
2
|
+
|
3
|
+
アソシエーションの定義に誤りがあるかもしれません。
|
2
4
|
|
3
5
|
|
4
6
|
|
1
質問内容,エラーページ,コードを変更しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[エラー]undefined method `
|
1
|
+
[エラー]NoMethodError in RoomsPersonal#show undefined method `content' for #<ActiveRecord::Relation []
|
test
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
チャット機能を作成中です。エラーの
|
1
|
+
チャット機能を作成中です。エラー内容にcontentが定義されていないという趣旨の文とRelationとの記述からモデルかマイグレーションの定義に問題があるとみて、messagesのマイグレーションファイルにcontentsカラムがあるのか確かめたところ、カラム名がcontentではなくmessageになっていたのでcontentに変更しました。しかしながら、また同じエラー文が表示されてしまいました。他マイグレーションファイルかモデルファイルの定義が間違っているのでしょうか? ご指摘願います。
|
2
2
|
|
3
|
+
|
4
|
+
|
3
|
-
|
5
|
+
*_message.html.erbはmessagesフォルダの中にあります。
|
6
|
+
|
7
|
+
|
4
8
|
|
5
9
|
|
6
10
|
|
@@ -10,13 +14,15 @@
|
|
10
14
|
|
11
15
|
```ここに言語を入力
|
12
16
|
|
13
|
-
<div class="message"
|
17
|
+
<div class="message">
|
14
18
|
|
15
|
-
<p><%= message.user.email %>: <%= l message.created_at, format: '%Y年%-m月%-d日(%a) %H:%M' %></p>
|
16
|
-
|
17
|
-
<%=
|
19
|
+
<p><%= message.content %></p>
|
18
20
|
|
19
21
|
</div>
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
20
26
|
|
21
27
|
```
|
22
28
|
|
@@ -24,13 +30,15 @@
|
|
24
30
|
|
25
31
|
```ここに言語を入力
|
26
32
|
|
33
|
+
<h1>Chat room</h1>
|
34
|
+
|
27
|
-
<div id="message
|
35
|
+
<div id="messages">
|
28
36
|
|
29
37
|
<%= render "messages/message", {message: @messages} %>
|
30
38
|
|
31
39
|
</div>
|
32
40
|
|
33
|
-
|
41
|
+
|
34
42
|
|
35
43
|
|
36
44
|
|
@@ -48,7 +56,7 @@
|
|
48
56
|
|
49
57
|
def show
|
50
58
|
|
51
|
-
@messages = Message.
|
59
|
+
@messages = Message.all
|
52
60
|
|
53
61
|
end
|
54
62
|
|
@@ -56,4 +64,58 @@
|
|
56
64
|
|
57
65
|
|
58
66
|
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
59
71
|
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
<message.rb>
|
76
|
+
|
77
|
+
```ここに言語を入力
|
78
|
+
|
79
|
+
class Message < ApplicationRecord
|
80
|
+
|
81
|
+
belongs_to :room
|
82
|
+
|
83
|
+
belongs_to :user
|
84
|
+
|
85
|
+
validates :content, presence: true
|
86
|
+
|
87
|
+
scope :recent, -> { order(created_at: :desc)}
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<create_message.rb>
|
96
|
+
|
97
|
+
```ここに言語を入力
|
98
|
+
|
99
|
+
class CreateMessages < ActiveRecord::Migration[6.0]
|
100
|
+
|
101
|
+
def change
|
102
|
+
|
103
|
+
create_table :messages do |t|
|
104
|
+
|
105
|
+
t.references :user, foreign_key: true
|
106
|
+
|
107
|
+
t.references :room, foreign_key: true
|
108
|
+
|
109
|
+
t.text :content, null: false
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
t.timestamps
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
```
|