質問編集履歴

2

補足をしました。

2020/01/23 09:01

投稿

yume0409
yume0409

スコア45

test CHANGED
File without changes
test CHANGED
@@ -109,3 +109,83 @@
109
109
 
110
110
 
111
111
  よろしくお願いします。
112
+
113
+
114
+
115
+
116
+
117
+ #補足
118
+
119
+ 回答ありがとうございます!
120
+
121
+ ```
122
+
123
+ def create
124
+
125
+ @tweet = Tweet.create(text: tweet_params[:text], user_id: current_user.id)
126
+
127
+ end
128
+
129
+
130
+
131
+ private
132
+
133
+ def tweet_params
134
+
135
+ params.permit(:text)
136
+
137
+ end
138
+
139
+ ```
140
+
141
+ createアクションはこのようにしました。
142
+
143
+ @tweet = を付け足して、redirect_to tweets_pathを消しました。
144
+
145
+ そしたら自動的にcreate.html.hamlが呼び出され、create.hrml.hamlは
146
+
147
+ ```
148
+
149
+ .chat-main
150
+
151
+ .tweets-block
152
+
153
+ .user-name
154
+
155
+ aaa
156
+
157
+ .messages
158
+
159
+ = @tweet.text
160
+
161
+ %i.fas.fa-ellipsis-h
162
+
163
+ = link_to "返信", "#", class: "reply"
164
+
165
+ .time
166
+
167
+ 時間
168
+
169
+ .tweets
170
+
171
+ = link_to new_tweets_path do
172
+
173
+ %i.fas.fa-pen
174
+
175
+ ```
176
+
177
+ このようにしました。
178
+
179
+ とりあえず、テキストの部分は反映されたのですが、その直後リロードするとshow.html.hamlに遷移され、
180
+
181
+ = @tweet.textを定義しても
182
+
183
+ ```
184
+
185
+ NoMethodError in Tweets#show
186
+
187
+ undefined method `text' for nil:NilClass
188
+
189
+ ```
190
+
191
+ というエラーが出ます。。。

1

誤字がありました。

2020/01/23 09:01

投稿

yume0409
yume0409

スコア45

test CHANGED
File without changes
test CHANGED
@@ -58,7 +58,7 @@
58
58
 
59
59
  #試した内容
60
60
 
61
- create.hrml.haml
61
+ create.html.haml
62
62
 
63
63
  ```
64
64