質問編集履歴

1

コードの記載

2021/06/23 12:55

投稿

saku27
saku27

スコア4

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,93 @@
7
7
 
8
8
 
9
9
  こちらのエラー何が原因でどのようにしたら解決できるかわかる方いらっしゃいますでしょうか?
10
+
11
+
12
+
13
+ ```class UsersController < ApplicationController
14
+
15
+ before_action :authenticate_user!
16
+
17
+ before_action :ensure_correct_user, only: [:edit, :update]
18
+
19
+
20
+
21
+ def show
22
+
23
+ @user = User.find(params[:id])
24
+
25
+ @book = Book.new
26
+
27
+ @books = Book.where(user_id: @user.id)
28
+
29
+ end
30
+
31
+
32
+
33
+ def index
34
+
35
+ @user = current_user
36
+
37
+ @users = User.all
38
+
39
+ @book = Book.new
40
+
41
+ @books = Book.all
42
+
43
+ end
44
+
45
+
46
+
47
+ def edit
48
+
49
+ @user = User.find(params[:id])
50
+
51
+ if @user == current_user
52
+
53
+ render "edit"
54
+
55
+ else
56
+
57
+ redirect_to user_path(current_user)
58
+
59
+ end
60
+
61
+ end
62
+
63
+
64
+
65
+ def update
66
+
67
+ @user = User.find(params[:id])
68
+
69
+ if @user.update(user_params)
70
+
71
+ flash[:notice]="You have updated user successfully."
72
+
73
+ redirect_to user_path(current_user)
74
+
75
+ else
76
+
77
+ render :edit
78
+
79
+ end
80
+
81
+ end
82
+
83
+
84
+
85
+ private
86
+
87
+ def user_params
88
+
89
+ params.require(:user).permit(:name, :profile_image, :introduction)
90
+
91
+ end
92
+
93
+
94
+
95
+ end
96
+
97
+ コード
98
+
99
+ ```