質問編集履歴
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,44 +43,6 @@
|
|
43
43
|
|
44
44
|
<p><%= @user.user_profile.image.present? ? @user.user_profile.image.filename : "添付ファイルなし" %></p>
|
45
45
|
|
46
|
-
|
47
|
-
<div class="card_container">
|
48
|
-
<div class="card_machine_title">
|
49
|
-
<div>
|
50
|
-
<p>ご担当者名</p>
|
51
|
-
</div>
|
52
|
-
</div>
|
53
|
-
<%= @user.user_profile.staff_name %>
|
54
|
-
</div>
|
55
|
-
|
56
|
-
<div class="card_container">
|
57
|
-
<div class="card_machine_title">
|
58
|
-
<div>
|
59
|
-
<p>ユーザー権限</p>
|
60
|
-
</div>
|
61
|
-
</div>
|
62
|
-
<%= I18n.t("enum.user_authorities.#{@user.user_authority}") %>
|
63
|
-
</div>
|
64
|
-
|
65
|
-
<div class="card_container">
|
66
|
-
<div class="card_machine_title">
|
67
|
-
<div>
|
68
|
-
<p>パートナーコード</p>
|
69
|
-
</div>
|
70
|
-
</div>
|
71
|
-
<%= @user.user_profile.partner_code %>
|
72
|
-
</div>
|
73
|
-
|
74
|
-
<div class="card_container">
|
75
|
-
<div class="card_machine_title">
|
76
|
-
<div>
|
77
|
-
<p>メールアドレス</p>
|
78
|
-
</div>
|
79
|
-
</div>
|
80
|
-
<%= @user.user_profile.email_address %>
|
81
|
-
</div>
|
82
|
-
|
83
|
-
|
84
46
|
<div class="row">
|
85
47
|
<div class="col-md-9"></div>
|
86
48
|
<%= link_to '戻る', :back, class: 'btn_back' %>
|
1
code 追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,6 +6,159 @@
|
|
6
6
|
|
7
7
|
確認画面で画像がうまく表示されません
|
8
8
|
|
9
|
+
view edit
|
10
|
+
```
|
11
|
+
|
12
|
+
<%=form_with(model: @userprofile, url: {action: 'confirm'}, method: 'put', local: true) do |f| %>
|
13
|
+
|
14
|
+
<div class="icon mx-auto">
|
15
|
+
<%= image_tag 'icon_profile.svg',{class: "icon mx-auto icon_avatar",id: 'preview'}%>
|
16
|
+
</div>
|
17
|
+
<%= f.file_field :image, accept: 'image/*', onchange: 'previewImage(this);' %>
|
18
|
+
|
19
|
+
|
20
|
+
<div class="icon mx-auto">
|
21
|
+
<%= image_tag 'icon_profile.svg',{class: "icon_avatar"}%>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
|
25
|
+
<div class="row">
|
26
|
+
<div class="col-md-9"></div>
|
27
|
+
<%= link_to '戻る', :back, class: 'btn_back' %>
|
28
|
+
<%= f.submit '確認', class: 'btn_dec' %>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
31
|
+
```
|
32
|
+
|
33
|
+
view confirm
|
34
|
+
```
|
35
|
+
|
36
|
+
<div class="icon mx-auto">
|
37
|
+
<% if @user.user_profile.image.attached? %>
|
38
|
+
<%= image_tag @user.user_profile.image ,{class: "icon_avatar"} %>
|
39
|
+
<% else %>
|
40
|
+
<%= image_tag 'icon_profile.svg',{class: "icon_avatar"} %>
|
41
|
+
<% end %>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<p><%= @user.user_profile.image.present? ? @user.user_profile.image.filename : "添付ファイルなし" %></p>
|
45
|
+
|
46
|
+
|
47
|
+
<div class="card_container">
|
48
|
+
<div class="card_machine_title">
|
49
|
+
<div>
|
50
|
+
<p>ご担当者名</p>
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
<%= @user.user_profile.staff_name %>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
<div class="card_container">
|
57
|
+
<div class="card_machine_title">
|
58
|
+
<div>
|
59
|
+
<p>ユーザー権限</p>
|
60
|
+
</div>
|
61
|
+
</div>
|
62
|
+
<%= I18n.t("enum.user_authorities.#{@user.user_authority}") %>
|
63
|
+
</div>
|
64
|
+
|
65
|
+
<div class="card_container">
|
66
|
+
<div class="card_machine_title">
|
67
|
+
<div>
|
68
|
+
<p>パートナーコード</p>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
<%= @user.user_profile.partner_code %>
|
72
|
+
</div>
|
73
|
+
|
74
|
+
<div class="card_container">
|
75
|
+
<div class="card_machine_title">
|
76
|
+
<div>
|
77
|
+
<p>メールアドレス</p>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
<%= @user.user_profile.email_address %>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
|
84
|
+
<div class="row">
|
85
|
+
<div class="col-md-9"></div>
|
86
|
+
<%= link_to '戻る', :back, class: 'btn_back' %>
|
87
|
+
<%= form_with(model: @userprofile ,url: user_path(@userprofile), method: 'put', local: true) do |f| %>
|
88
|
+
<%= f.hidden_field :image %>
|
89
|
+
<%= f.hidden_field :staff_name %>
|
90
|
+
<%= f.hidden_field :user_authority, :value => @user.user_authority %>
|
91
|
+
<%= f.hidden_field :partner_code %>
|
92
|
+
<%= f.hidden_field :email_address %>
|
93
|
+
<%= f.submit '保存', class: 'btn_dec' %>
|
94
|
+
<% end %>
|
95
|
+
</div>
|
96
|
+
```
|
97
|
+
|
98
|
+
|
99
|
+
controller
|
100
|
+
```
|
101
|
+
|
102
|
+
def edit
|
103
|
+
@title = 'ユーザー変更'
|
104
|
+
@user = User.find(params[:id])
|
105
|
+
@userprofile = @user.user_profile
|
106
|
+
end
|
107
|
+
|
108
|
+
def confirm
|
109
|
+
logger.debug "************************: [#{params.inspect}]"
|
110
|
+
|
111
|
+
@user = User.find(params[:id])
|
112
|
+
|
113
|
+
@user.user_authority = users_params[:user_authority]
|
114
|
+
@user.user_profile.image = users_params[:image]
|
115
|
+
@user.user_profile.email_address = users_params[:email_address]
|
116
|
+
@user.user_profile.partner_code = users_params[:partner_code]
|
117
|
+
@user.user_profile.staff_name = users_params[:staff_name]
|
118
|
+
@userprofile = @user.user_profile
|
119
|
+
|
120
|
+
logger.debug "************************: [#{@user.inspect}]"
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def update
|
125
|
+
@title = 'ユーザー変更'
|
126
|
+
@user = User.find(params[:id])
|
127
|
+
# @userprofile = @user.user_profile
|
128
|
+
logger.debug "************************: [#{params.inspect}]"
|
129
|
+
logger.debug "************************: [#{users_params.inspect}]"
|
130
|
+
|
131
|
+
@user.user_authority = users_params[:user_authority]
|
132
|
+
@user.user_profile.image = users_params[:image]
|
133
|
+
@user.user_profile.email_address = users_params[:email_address]
|
134
|
+
@user.user_profile.partner_code = users_params[:partner_code]
|
135
|
+
@user.user_profile.staff_name = users_params[:staff_name]
|
136
|
+
|
137
|
+
# byebug
|
138
|
+
if @user.user_profile.save! && @user.save!
|
139
|
+
post = e.record
|
140
|
+
post.image = nil
|
141
|
+
redirect_to users_path(@userprofile),notice: '更新されました'
|
142
|
+
else
|
143
|
+
flash.now[:error] = '更新できませんでした'
|
144
|
+
render :edit
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def users_params
|
151
|
+
# puts "------------------"
|
152
|
+
# puts users_params
|
153
|
+
# puts "-----------------"
|
154
|
+
params.require(:user_profile).permit(:user_authority,:image, :email_address, :partner_code, :staff_name)
|
155
|
+
end
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
9
162
|
### 実行したこと
|
10
163
|
|
11
164
|
https://qiita.com/hayashiki/items/40a58e4ff56973775cea
|