質問編集履歴
5
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -232,4 +232,122 @@
|
|
232
232
|
|
233
233
|
|
234
234
|
|
235
|
+
users_controller.rb
|
236
|
+
|
237
|
+
```
|
238
|
+
|
239
|
+
class UsersController < ApplicationController
|
240
|
+
|
241
|
+
before_action :require_user_logged_in, only: [:index, :show, :followings, :followers, :likes]
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
def index
|
246
|
+
|
247
|
+
@users = User.order(id: :desc).page(params[:page]).per(25)
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
def show
|
254
|
+
|
255
|
+
@user = User.find(params[:id])
|
256
|
+
|
257
|
+
@microposts = @user.microposts.order(id: :desc).page(params[:page])
|
258
|
+
|
259
|
+
counts(@user)
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
def new
|
266
|
+
|
267
|
+
@user = User.new
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
def create
|
274
|
+
|
275
|
+
@user = User.new(user_params)
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
if @user.save
|
280
|
+
|
281
|
+
flash[:success] = 'ユーザを登録しました。'
|
282
|
+
|
283
|
+
redirect_to @user
|
284
|
+
|
285
|
+
else
|
286
|
+
|
287
|
+
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
288
|
+
|
289
|
+
render :new
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
def followings
|
298
|
+
|
299
|
+
@user = User.find(params[:id])
|
300
|
+
|
301
|
+
@followings = @user.followings.page(params[:page])
|
302
|
+
|
303
|
+
counts(@user)
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
def followers
|
310
|
+
|
311
|
+
@user = User.find(params[:id])
|
312
|
+
|
313
|
+
@followers = @user.followers.page(params[:page])
|
314
|
+
|
315
|
+
counts(@user)
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
def likes
|
322
|
+
|
323
|
+
@user = User.find(params[:id])
|
324
|
+
|
325
|
+
@likes = @user.likes.page(params[:page])
|
326
|
+
|
327
|
+
counts(@user)
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
private
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
def user_params
|
338
|
+
|
339
|
+
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
```
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
235
353
|
![イメージ説明](8c1dbddc9b097dcdf07eda7c97e550e3.png)
|
4
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -228,10 +228,6 @@
|
|
228
228
|
|
229
229
|
end
|
230
230
|
|
231
|
-
|
232
|
-
|
233
|
-
コード
|
234
|
-
|
235
231
|
```
|
236
232
|
|
237
233
|
|
3
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,4 +154,86 @@
|
|
154
154
|
|
155
155
|
|
156
156
|
|
157
|
+
microposts_controller.rb
|
158
|
+
|
159
|
+
```ここに言語を入力
|
160
|
+
|
161
|
+
class MicropostsController < ApplicationController
|
162
|
+
|
163
|
+
before_action :require_user_logged_in
|
164
|
+
|
165
|
+
before_action :correct_user, only: [:destroy]
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
def create
|
170
|
+
|
171
|
+
@micropost = current_user.microposts.build(micropost_params)
|
172
|
+
|
173
|
+
if @micropost.save
|
174
|
+
|
175
|
+
flash[:success] = "メッセージを投稿しました。"
|
176
|
+
|
177
|
+
redirect_to root_url
|
178
|
+
|
179
|
+
else
|
180
|
+
|
181
|
+
@microposts = current_user.feed_microposts.order(id: :desc).page(params[:page])
|
182
|
+
|
183
|
+
flash.now[:danger] = "メッセージの投稿に失敗しました。"
|
184
|
+
|
185
|
+
render "toppages/index"
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
def destroy
|
194
|
+
|
195
|
+
@micropost.destroy
|
196
|
+
|
197
|
+
flash[:success] = "メッセージを削除しました。"
|
198
|
+
|
199
|
+
redirect_back(fallback_location: root_path)
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
private
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
def micropost_params
|
210
|
+
|
211
|
+
params.require(:micropost).permit(:content)
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
def correct_user
|
218
|
+
|
219
|
+
@micropost = current_user.microposts.find_by(id: params[:id])
|
220
|
+
|
221
|
+
unless @micropost
|
222
|
+
|
223
|
+
redirect_to root_url
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
コード
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
|
238
|
+
|
157
239
|
![イメージ説明](8c1dbddc9b097dcdf07eda7c97e550e3.png)
|
2
画像の挿入
test
CHANGED
File without changes
|
test
CHANGED
@@ -151,3 +151,7 @@
|
|
151
151
|
</div>
|
152
152
|
|
153
153
|
```
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
![イメージ説明](8c1dbddc9b097dcdf07eda7c97e550e3.png)
|
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,17 @@
|
|
2
2
|
|
3
3
|
わかるかたご教授お願いします。
|
4
4
|
|
5
|
+
|
6
|
+
|
7
|
+
NoMethodError in Users#likes
|
8
|
+
|
9
|
+
|
10
|
+
|
5
11
|
undefined method `each' for nil:NilClass
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
恐らくlikes.html.erbのどこかがおかしいのだと思います
|
6
16
|
|
7
17
|
|
8
18
|
|