質問編集履歴

2

修正

2021/06/18 12:13

投稿

Kotakoyama
Kotakoyama

スコア1

test CHANGED
File without changes
test CHANGED
@@ -88,106 +88,30 @@
88
88
 
89
89
 
90
90
 
91
-
92
-
93
- <div class="card_container">
91
+ <div class="row">
94
-
92
+
95
- <div class="card_machine_title">
93
+ <div class="col-md-9"></div>
96
-
94
+
97
- <div>
95
+ <%= link_to '戻る', :back, class: 'btn_back' %>
96
+
98
-
97
+ <%= form_with(model: @userprofile ,url: user_path(@userprofile), method: 'put', local: true) do |f| %>
98
+
99
- <p>ご担当者名</p>
99
+ <%= f.hidden_field :image %>
100
-
101
- </div>
100
+
102
-
103
- </div>
104
-
105
- <%= @user.user_profile.staff_name %>
101
+ <%= f.hidden_field :staff_name %>
102
+
103
+ <%= f.hidden_field :user_authority, :value => @user.user_authority %>
104
+
105
+ <%= f.hidden_field :partner_code %>
106
+
107
+ <%= f.hidden_field :email_address %>
108
+
109
+ <%= f.submit '保存', class: 'btn_dec' %>
110
+
111
+ <% end %>
106
112
 
107
113
  </div>
108
114
 
109
-
110
-
111
- <div class="card_container">
112
-
113
- <div class="card_machine_title">
114
-
115
- <div>
116
-
117
- <p>ユーザー権限</p>
118
-
119
- </div>
120
-
121
- </div>
122
-
123
- <%= I18n.t("enum.user_authorities.#{@user.user_authority}") %>
124
-
125
- </div>
126
-
127
-
128
-
129
- <div class="card_container">
130
-
131
- <div class="card_machine_title">
132
-
133
- <div>
134
-
135
- <p>パートナーコード</p>
136
-
137
- </div>
138
-
139
- </div>
140
-
141
- <%= @user.user_profile.partner_code %>
142
-
143
- </div>
144
-
145
-
146
-
147
- <div class="card_container">
148
-
149
- <div class="card_machine_title">
150
-
151
- <div>
152
-
153
- <p>メールアドレス</p>
154
-
155
- </div>
156
-
157
- </div>
158
-
159
- <%= @user.user_profile.email_address %>
160
-
161
- </div>
162
-
163
-
164
-
165
-
166
-
167
- <div class="row">
168
-
169
- <div class="col-md-9"></div>
170
-
171
- <%= link_to '戻る', :back, class: 'btn_back' %>
172
-
173
- <%= form_with(model: @userprofile ,url: user_path(@userprofile), method: 'put', local: true) do |f| %>
174
-
175
- <%= f.hidden_field :image %>
176
-
177
- <%= f.hidden_field :staff_name %>
178
-
179
- <%= f.hidden_field :user_authority, :value => @user.user_authority %>
180
-
181
- <%= f.hidden_field :partner_code %>
182
-
183
- <%= f.hidden_field :email_address %>
184
-
185
- <%= f.submit '保存', class: 'btn_dec' %>
186
-
187
- <% end %>
188
-
189
- </div>
190
-
191
115
  ```
192
116
 
193
117
 

1

code 追記

2021/06/18 12:13

投稿

Kotakoyama
Kotakoyama

スコア1

test CHANGED
File without changes
test CHANGED
@@ -14,6 +14,312 @@
14
14
 
15
15
 
16
16
 
17
+ view edit
18
+
19
+ ```
20
+
21
+
22
+
23
+ <%=form_with(model: @userprofile, url: {action: 'confirm'}, method: 'put', local: true) do |f| %>
24
+
25
+
26
+
27
+ <div class="icon mx-auto">
28
+
29
+ <%= image_tag 'icon_profile.svg',{class: "icon mx-auto icon_avatar",id: 'preview'}%>
30
+
31
+ </div>
32
+
33
+ <%= f.file_field :image, accept: 'image/*', onchange: 'previewImage(this);' %>
34
+
35
+
36
+
37
+
38
+
39
+ <div class="icon mx-auto">
40
+
41
+ <%= image_tag 'icon_profile.svg',{class: "icon_avatar"}%>
42
+
43
+ </div>
44
+
45
+
46
+
47
+
48
+
49
+ <div class="row">
50
+
51
+ <div class="col-md-9"></div>
52
+
53
+ <%= link_to '戻る', :back, class: 'btn_back' %>
54
+
55
+ <%= f.submit '確認', class: 'btn_dec' %>
56
+
57
+ </div>
58
+
59
+ <% end %>
60
+
61
+ ```
62
+
63
+
64
+
65
+ view confirm
66
+
67
+ ```
68
+
69
+
70
+
71
+ <div class="icon mx-auto">
72
+
73
+ <% if @user.user_profile.image.attached? %>
74
+
75
+ <%= image_tag @user.user_profile.image ,{class: "icon_avatar"} %>
76
+
77
+ <% else %>
78
+
79
+ <%= image_tag 'icon_profile.svg',{class: "icon_avatar"} %>
80
+
81
+ <% end %>
82
+
83
+ </div>
84
+
85
+
86
+
87
+ <p><%= @user.user_profile.image.present? ? @user.user_profile.image.filename : "添付ファイルなし" %></p>
88
+
89
+
90
+
91
+
92
+
93
+ <div class="card_container">
94
+
95
+ <div class="card_machine_title">
96
+
97
+ <div>
98
+
99
+ <p>ご担当者名</p>
100
+
101
+ </div>
102
+
103
+ </div>
104
+
105
+ <%= @user.user_profile.staff_name %>
106
+
107
+ </div>
108
+
109
+
110
+
111
+ <div class="card_container">
112
+
113
+ <div class="card_machine_title">
114
+
115
+ <div>
116
+
117
+ <p>ユーザー権限</p>
118
+
119
+ </div>
120
+
121
+ </div>
122
+
123
+ <%= I18n.t("enum.user_authorities.#{@user.user_authority}") %>
124
+
125
+ </div>
126
+
127
+
128
+
129
+ <div class="card_container">
130
+
131
+ <div class="card_machine_title">
132
+
133
+ <div>
134
+
135
+ <p>パートナーコード</p>
136
+
137
+ </div>
138
+
139
+ </div>
140
+
141
+ <%= @user.user_profile.partner_code %>
142
+
143
+ </div>
144
+
145
+
146
+
147
+ <div class="card_container">
148
+
149
+ <div class="card_machine_title">
150
+
151
+ <div>
152
+
153
+ <p>メールアドレス</p>
154
+
155
+ </div>
156
+
157
+ </div>
158
+
159
+ <%= @user.user_profile.email_address %>
160
+
161
+ </div>
162
+
163
+
164
+
165
+
166
+
167
+ <div class="row">
168
+
169
+ <div class="col-md-9"></div>
170
+
171
+ <%= link_to '戻る', :back, class: 'btn_back' %>
172
+
173
+ <%= form_with(model: @userprofile ,url: user_path(@userprofile), method: 'put', local: true) do |f| %>
174
+
175
+ <%= f.hidden_field :image %>
176
+
177
+ <%= f.hidden_field :staff_name %>
178
+
179
+ <%= f.hidden_field :user_authority, :value => @user.user_authority %>
180
+
181
+ <%= f.hidden_field :partner_code %>
182
+
183
+ <%= f.hidden_field :email_address %>
184
+
185
+ <%= f.submit '保存', class: 'btn_dec' %>
186
+
187
+ <% end %>
188
+
189
+ </div>
190
+
191
+ ```
192
+
193
+
194
+
195
+
196
+
197
+ controller
198
+
199
+ ```
200
+
201
+
202
+
203
+ def edit
204
+
205
+ @title = 'ユーザー変更'
206
+
207
+ @user = User.find(params[:id])
208
+
209
+ @userprofile = @user.user_profile
210
+
211
+ end
212
+
213
+
214
+
215
+ def confirm
216
+
217
+ logger.debug "************************: [#{params.inspect}]"
218
+
219
+
220
+
221
+ @user = User.find(params[:id])
222
+
223
+
224
+
225
+ @user.user_authority = users_params[:user_authority]
226
+
227
+ @user.user_profile.image = users_params[:image]
228
+
229
+ @user.user_profile.email_address = users_params[:email_address]
230
+
231
+ @user.user_profile.partner_code = users_params[:partner_code]
232
+
233
+ @user.user_profile.staff_name = users_params[:staff_name]
234
+
235
+ @userprofile = @user.user_profile
236
+
237
+
238
+
239
+ logger.debug "************************: [#{@user.inspect}]"
240
+
241
+
242
+
243
+ end
244
+
245
+
246
+
247
+ def update
248
+
249
+ @title = 'ユーザー変更'
250
+
251
+ @user = User.find(params[:id])
252
+
253
+ # @userprofile = @user.user_profile
254
+
255
+ logger.debug "************************: [#{params.inspect}]"
256
+
257
+ logger.debug "************************: [#{users_params.inspect}]"
258
+
259
+
260
+
261
+ @user.user_authority = users_params[:user_authority]
262
+
263
+ @user.user_profile.image = users_params[:image]
264
+
265
+ @user.user_profile.email_address = users_params[:email_address]
266
+
267
+ @user.user_profile.partner_code = users_params[:partner_code]
268
+
269
+ @user.user_profile.staff_name = users_params[:staff_name]
270
+
271
+
272
+
273
+ # byebug
274
+
275
+ if @user.user_profile.save! && @user.save!
276
+
277
+ post = e.record
278
+
279
+ post.image = nil
280
+
281
+ redirect_to users_path(@userprofile),notice: '更新されました'
282
+
283
+ else
284
+
285
+ flash.now[:error] = '更新できませんでした'
286
+
287
+ render :edit
288
+
289
+ end
290
+
291
+ end
292
+
293
+
294
+
295
+ private
296
+
297
+
298
+
299
+ def users_params
300
+
301
+ # puts "------------------"
302
+
303
+ # puts users_params
304
+
305
+ # puts "-----------------"
306
+
307
+ params.require(:user_profile).permit(:user_authority,:image, :email_address, :partner_code, :staff_name)
308
+
309
+ end
310
+
311
+
312
+
313
+ ```
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
17
323
  ### 実行したこと
18
324
 
19
325