質問編集履歴
1
updateアクションないを変更しました!
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
permitted: false の解決法
|
test
CHANGED
@@ -2,25 +2,19 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
タイトルに記載しました、 permitted:falseのエラーでつまずいています。
|
6
|
-
|
6
|
+
|
7
|
-
|
7
|
+
調べてみると、ストロングパラメータの記載に問題があるのだということが分かったのですが、
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
11
|
-
|
9
|
+
下記に記載している通り、users_controller.rbの下部(private)にparams.requireを追記したのですが変わりません。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
|
12
|
+
|
19
|
-
ご教授、よろしくお願いいたします!
|
13
|
+
ご教授のほど、よろしくお願いいたします!!
|
20
14
|
|
21
15
|
### 発生している問題・エラーメッセージ
|
22
16
|
|
23
|
-
|
17
|
+
permitted: false
|
24
18
|
|
25
19
|
|
26
20
|
|
@@ -28,15 +22,83 @@
|
|
28
22
|
|
29
23
|
|
30
24
|
|
31
|
-
|
25
|
+
```エラ〜メッセージ
|
26
|
+
|
27
|
+
<ActionController::Parameters {"utf8"=>"✓", "authenticity_token"=>"0nEBSbJ5+7+dhMOi8avmT7lpopkdZgqIFGreJnWP2alMQ+dMH/TKIMi8y+YM/ZXf/JI8WQBJJ3AIKesxe0KTpA==", "name"=>"べべべ", "image"=>#<ActionDispatch::Http::UploadedFile:0x00007f86e0469538 @tempfile=#<Tempfile:/var/folders/4j/366dq7y542n_xt2k1d5bq32w0000gn/T/RackMultipart20201014-2391-13b8a4d.png>, @original_filename="スクリーンショット 2020-10-02 18.16.34.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"image\"; filename=\"\xE3\x82\xB9\xE3\x82\xAF\xE3\x83\xAA\xE3\x83\xBC\xE3\x83\xB3\xE3\x82\xB7\xE3\x83\xA7\xE3\x83\x83\xE3\x83\x88 2020-10-02 18.16.34.png\"\r\nContent-Type: image/png\r\n">, "bgimage"=>#<ActionDispatch::Http::UploadedFile:0x00007f86e0490e58 @tempfile=#<Tempfile:/var/folders/4j/366dq7y542n_xt2k1d5bq32w0000gn/T/RackMultipart20201014-2391-1exzwwp.jpg>, @original_filename="sean-o-KMn4VEeEPR8-unsplashのコピー.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"bgimage\"; filename=\"sean-o-KMn4VEeEPR8-unsplash\xE3\x81\xAE\xE3\x82\xB3\xE3\x83\x92\xE3\x82\x9A\xE3\x83\xBC.jpg\"\r\nContent-Type: image/jpeg\r\n">, "intro"=>"かか", "controller"=>"users", "action"=>"update", "id"=>"3"} permitted: false>
|
28
|
+
|
29
|
+
```
|
30
|
+
|
31
|
+
ソースコード
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```rails
|
36
|
+
|
37
|
+
class UsersController < ApplicationController
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
before_action :set_user, only: [:show,:update,:edit,:delete]
|
42
|
+
|
43
|
+
def new
|
44
|
+
|
45
|
+
@user = User.new
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def create
|
52
|
+
|
53
|
+
@user = User.new(name: params[:name], email: params[:email], password: params[:password], image: "emma-smith-NS_DMD4rEjk-unsplash.jpg", bgimage: "自然壁画.jpg") # 実装は終わっていないことに注意!
|
54
|
+
|
55
|
+
# binding.pry
|
56
|
+
|
57
|
+
if @user.save
|
58
|
+
|
59
|
+
session[:user_id] = @user.id
|
60
|
+
|
61
|
+
flash[:success] = "Welcome to this app!"
|
62
|
+
|
63
|
+
redirect_to("/home/about")
|
64
|
+
|
65
|
+
else
|
66
|
+
|
67
|
+
flash[:notice] = "Your email is already existed"
|
68
|
+
|
69
|
+
render 'users/new'
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
def show
|
78
|
+
|
79
|
+
@users = User.find_by(id: params[:id])
|
80
|
+
|
81
|
+
# binding.pry
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
def edit
|
88
|
+
|
89
|
+
@users = User.find_by(id: params[:id])
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def update
|
32
98
|
|
33
99
|
|
34
100
|
|
35
|
-
@users = User.find_by(id:
|
101
|
+
@users = User.find_by(id: params[:id])
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if @users.update(
|
40
102
|
|
41
103
|
@users.name = params[:name],
|
42
104
|
|
@@ -44,7 +106,11 @@
|
|
44
106
|
|
45
107
|
@users.bgimage = params[:bgimage],
|
46
108
|
|
47
|
-
@users.intro = params[:intro]
|
109
|
+
@users.intro = params[:intro]
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
if @users.save
|
48
114
|
|
49
115
|
# binding.pry
|
50
116
|
|
@@ -60,15 +126,97 @@
|
|
60
126
|
|
61
127
|
end
|
62
128
|
|
129
|
+
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
def login_form
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def login
|
142
|
+
|
143
|
+
@user = User.find_by(email: params[:email])
|
144
|
+
|
145
|
+
if @user && @user.authenticate(params[:password])
|
146
|
+
|
147
|
+
session[:user_id] = @user.id
|
148
|
+
|
149
|
+
flash[:success] = "welcome Back"
|
150
|
+
|
151
|
+
redirect_to ("/home/about")
|
152
|
+
|
153
|
+
else
|
154
|
+
|
155
|
+
@error_message = "Wrong email or password"
|
156
|
+
|
157
|
+
@email = params[:email]
|
158
|
+
|
159
|
+
@password = params[:password]
|
160
|
+
|
161
|
+
render("/users/login_form")
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
def logout
|
170
|
+
|
171
|
+
session[:user_id] = nil
|
172
|
+
|
173
|
+
flash[:notice] = "Logout"
|
174
|
+
|
175
|
+
redirect_to("/home/about")
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def user_params
|
190
|
+
|
191
|
+
params.require(:user).permit(:name, :image, :bgimage, :intro)
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
def set_user
|
198
|
+
|
199
|
+
#特定データの取得
|
200
|
+
|
201
|
+
@user = User.find_by(params[:id])
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
```
|
210
|
+
|
211
|
+
|
212
|
+
|
63
|
-
|
213
|
+
```erb
|
64
|
-
|
65
|
-
|
66
214
|
|
67
215
|
<div class="edit_profile-wrapper">
|
68
216
|
|
69
217
|
<%= @users.name %>
|
70
218
|
|
71
|
-
<%= form_tag("/users/#{@
|
219
|
+
<%= form_tag("/users/#{@users.id}/update", {multipart: true}) do %>
|
72
220
|
|
73
221
|
|
74
222
|
|
@@ -78,7 +226,7 @@
|
|
78
226
|
|
79
227
|
<label for="name"></label>
|
80
228
|
|
81
|
-
<input type="text" name="name" value="<%=@
|
229
|
+
<input type="text" name="name" value="<%=@users.name%>" required>
|
82
230
|
|
83
231
|
</div>
|
84
232
|
|
@@ -106,7 +254,7 @@
|
|
106
254
|
|
107
255
|
<p>自己紹介文</p>
|
108
256
|
|
109
|
-
<textarea class="input-text" type="text" placeholder=" enter your introduction!" name="intro"></textarea>
|
257
|
+
<textarea class="input-text" type="text" placeholder=" enter your introduction!" name="intro" value="<%=@users.intro%>"></textarea>
|
110
258
|
|
111
259
|
</div>
|
112
260
|
|
@@ -118,6 +266,8 @@
|
|
118
266
|
|
119
267
|
</div>
|
120
268
|
|
269
|
+
```
|
270
|
+
|
121
271
|
|
122
272
|
|
123
273
|
### 試したこと
|