質問編集履歴
1
情報の追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Rails update
|
1
|
+
Rails updateしようとするも、カラの値が保存されてしまう。
|
test
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
### やりたいこと
|
2
2
|
|
3
|
-
現在制作中のアプリのマイページ(ニックネーム、
|
3
|
+
現在制作中のアプリのマイページ(ニックネーム、自己紹介文)を編集するページを制作しております。
|
4
|
-
|
4
|
+
|
5
|
-
ニックネーム、
|
5
|
+
ニックネーム、自己紹介文の2つの項目を同時に更新する処理になります。
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
### 発生している問題
|
10
10
|
|
11
|
-
|
11
|
+
データ自体はアップデート出来ており、完了のフラッシュも表示されているのですが、:nameと:introductionがカラになって保存されてしまいます。
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
-
![イメージ説明](1be
|
15
|
+
![イメージ説明](2bc545e19d68bedd728ff177ec0c159a.png)
|
16
|
-
|
17
|
-
![イメージ説明](fdc0edf23e539db67710c79e4f8d515a.png)
|
18
16
|
|
19
17
|
### コード
|
20
18
|
|
@@ -40,7 +38,7 @@
|
|
40
38
|
|
41
39
|
@user = User.find(current_user.id)
|
42
40
|
|
43
|
-
if @user.update(name: params[:name],
|
41
|
+
if @user.update(name: params[:name], introduction: params[:introduction])
|
44
42
|
|
45
43
|
flash[:edit_success] = '編集されました'
|
46
44
|
|
@@ -72,10 +70,6 @@
|
|
72
70
|
|
73
71
|
<%= f.text_field :name %><br>
|
74
72
|
|
75
|
-
<%= f.label :email, 'メールアドレス' %>
|
76
|
-
|
77
|
-
<%= f.email_field :email %><br>
|
78
|
-
|
79
73
|
<%= f.label :introduction, '自己紹介文' %>
|
80
74
|
|
81
75
|
<%= f.text_area :introduction %><br>
|
@@ -90,68 +84,126 @@
|
|
90
84
|
|
91
85
|
### 送信時のログ
|
92
86
|
|
87
|
+
|
88
|
+
|
93
|
-
Started GET "/mypages/edit" for ::1 at 2020-12-06 1
|
89
|
+
Started GET "/mypages/edit" for ::1 at 2020-12-06 21:58:07 +0900
|
94
90
|
|
95
91
|
Processing by MypagesController#edit as HTML
|
96
92
|
|
97
|
-
User Load (0.
|
93
|
+
User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1
|
98
|
-
|
94
|
+
|
99
|
-
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
95
|
+
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
100
|
-
|
96
|
+
|
101
|
-
User Load (0.
|
97
|
+
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
|
102
98
|
|
103
99
|
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
104
100
|
|
105
101
|
Rendering mypages/edit.html.erb within layouts/application
|
106
102
|
|
107
|
-
Rendered mypages/edit.html.erb within layouts/application (Duration:
|
103
|
+
Rendered mypages/edit.html.erb within layouts/application (Duration: 8.1ms | Allocations: 418)
|
108
104
|
|
109
105
|
[Webpacker] Everything's up-to-date. Nothing to do
|
110
106
|
|
111
|
-
Rendered layouts/_flash.scores.html.erb (Duration: 0.
|
107
|
+
Rendered layouts/_flash.scores.html.erb (Duration: 0.4ms | Allocations: 18)
|
108
|
+
|
112
|
-
|
109
|
+
Completed 200 OK in 61ms (Views: 40.7ms | ActiveRecord: 1.2ms | Allocations: 6060)
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
Started GET "/mypages/edit" for ::1 at 2020-12-06 21:58:23 +0900
|
116
|
+
|
117
|
+
Processing by MypagesController#edit as HTML
|
118
|
+
|
119
|
+
User Load (3.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1
|
120
|
+
|
121
|
+
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
122
|
+
|
123
|
+
User Load (1.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
|
124
|
+
|
125
|
+
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
126
|
+
|
127
|
+
Rendering mypages/edit.html.erb within layouts/application
|
128
|
+
|
129
|
+
Rendered mypages/edit.html.erb within layouts/application (Duration: 1.8ms | Allocations: 427)
|
130
|
+
|
131
|
+
[Webpacker] Everything's up-to-date. Nothing to do
|
132
|
+
|
133
|
+
Rendered layouts/_flash.scores.html.erb (Duration: 0.0ms | Allocations: 18)
|
134
|
+
|
113
|
-
Completed 200 OK in
|
135
|
+
Completed 200 OK in 40ms (Views: 27.6ms | ActiveRecord: 4.5ms | Allocations: 6076)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
119
|
-
Started PATCH "/users/3" for ::1 at 2020-12-06 1
|
141
|
+
Started PATCH "/users/3" for ::1 at 2020-12-06 21:58:27 +0900
|
120
142
|
|
121
143
|
Processing by UsersController#update as HTML
|
122
144
|
|
123
|
-
Parameters: {"authenticity_token"=>"
|
124
|
-
|
125
|
-
User Load (
|
145
|
+
Parameters: {"authenticity_token"=>"X9EBAkaYwjpkC7MgwRU8/8otTrZjeCOA1vbQIUvP+10AQ0iajpemNKzNn0y3FLXA2ZMgJFXL093hkcDurgK6CA==", "user"=>{"name"=>"あや", "introduction"=>"あやですよ。"}, "commit"=>"編集する", "id"=>"3"}
|
146
|
+
|
147
|
+
User Load (5.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1
|
126
148
|
|
127
149
|
↳ app/controllers/users_controller.rb:35:in `update'
|
128
150
|
|
129
|
-
User Load (0.
|
151
|
+
User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
|
130
152
|
|
131
153
|
↳ app/controllers/users_controller.rb:35:in `update'
|
132
154
|
|
133
|
-
|
155
|
+
(6.5ms) BEGIN
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
156
|
+
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
app/controllers/users_controller.rb:36:in `update'
|
157
|
+
↳ app/controllers/users_controller.rb:36:in `update'
|
158
|
+
|
146
|
-
|
159
|
+
User Update (4.6ms) UPDATE `users` SET `users`.`name` = NULL, `users`.`introduction` = NULL, `users`.`updated_at` = '2020-12-06 12:58:27.921384' WHERE `users`.`id` = 3
|
160
|
+
|
147
|
-
|
161
|
+
↳ app/controllers/users_controller.rb:36:in `update'
|
162
|
+
|
163
|
+
(6.1ms) COMMIT
|
164
|
+
|
165
|
+
↳ app/controllers/users_controller.rb:36:in `update'
|
166
|
+
|
167
|
+
Redirected to http://localhost:3000/mypages/edit
|
168
|
+
|
169
|
+
Completed 302 Found in 43ms (ActiveRecord: 23.5ms | Allocations: 4740)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
Started GET "/mypages/edit" for ::1 at 2020-12-06 21:58:27 +0900
|
176
|
+
|
177
|
+
Processing by MypagesController#edit as HTML
|
178
|
+
|
179
|
+
User Load (3.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 ORDER BY `users`.`id` ASC LIMIT 1
|
180
|
+
|
181
|
+
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
182
|
+
|
183
|
+
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 3 LIMIT 1
|
184
|
+
|
185
|
+
↳ app/controllers/mypages_controller.rb:6:in `edit'
|
186
|
+
|
187
|
+
Rendering mypages/edit.html.erb within layouts/application
|
188
|
+
|
189
|
+
Rendered mypages/edit.html.erb within layouts/application (Duration: 1.0ms | Allocations: 418)
|
190
|
+
|
191
|
+
[Webpacker] Everything's up-to-date. Nothing to do
|
192
|
+
|
193
|
+
Rendered layouts/_flash.scores.html.erb (Duration: 0.1ms | Allocations: 19)
|
194
|
+
|
195
|
+
Completed 200 OK in 17ms (Views: 7.1ms | ActiveRecord: 3.4ms | Allocations: 6076)
|
148
196
|
|
149
197
|
### やったみたこと
|
150
198
|
|
151
|
-
|
199
|
+
emailアドレスの変更もしようとしていましたが、deviseの影響かわかりませんが、バリデーションで弾かれたので、今回は名前と自己紹介文のみとしました。
|
152
|
-
|
200
|
+
|
153
|
-
|
201
|
+
ログをみると、UPDATE `users` SET `users`.`name` = NULL, `users`.`introduction` = NULL, と書いてあり、update出来ていることはわかるのですが、値が全てNULLとなってしまっています。view側から値が渡っていないと思われます。
|
202
|
+
|
203
|
+
|
204
|
+
|
154
|
-
|
205
|
+
ひとつ気になっているのは、viewは/mypages/editなのですが、controllerはusers_controllerの#updateで処理させているのですが、問題ないのでしょうか。
|
155
|
-
|
156
|
-
|
206
|
+
|
207
|
+
|
208
|
+
|
157
|
-
|
209
|
+
情報不足かもしれませんが、宜しくお願い致します。
|