質問編集履歴

3

environment.rb と言う間違ったファイル名を deveropment.rb に変更致しました。

2021/12/01 06:54

投稿

punchan36
punchan36

スコア105

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- **config/environment/environment.rb**
31
+ **config/environment/deveropment.rb**
32
32
 
33
33
  ```ruby
34
34
 

2

画像周りのコードを追記致しました。

2021/12/01 06:54

投稿

punchan36
punchan36

スコア105

test CHANGED
File without changes
test CHANGED
@@ -115,3 +115,117 @@
115
115
  heroku/7.59.2 win32-x64 node-v12.21.0
116
116
 
117
117
  VIM - Vi IMproved 8.2
118
+
119
+
120
+
121
+ ### 画像周りのコードの追記
122
+
123
+
124
+
125
+ **users_controller.rb**
126
+
127
+ ```ruby
128
+
129
+ class UsersController < ApplicationController
130
+
131
+ def update
132
+
133
+ @user = User.find_by(id: params[:id])
134
+
135
+ @user.name = params[:name]
136
+
137
+ if params[:image]
138
+
139
+ @user.image_name = "#{@user.id}.jpg"
140
+
141
+ image = params[:image]
142
+
143
+ File.binwrite("public/user_images/#{@user.image_name}", image.read)
144
+
145
+ end
146
+
147
+ if params[:cover_image]
148
+
149
+ @user.cover_image_name = "#{@user.id}_cover.jpg"
150
+
151
+ cover_image = params[:cover_image]
152
+
153
+ File.binwrite("public/user_cover_images/#{@user.cover_image_name}", cover_image.read)
154
+
155
+ end
156
+
157
+ if @user.save
158
+
159
+ flash[:notice] = "You have successfully updated your profile"
160
+
161
+ redirect_to("/users/#{@user.id}")
162
+
163
+ else
164
+
165
+ render("users/edit")
166
+
167
+ end
168
+
169
+ end
170
+
171
+ end
172
+
173
+ ```
174
+
175
+
176
+
177
+ **users/edit.html.erb**
178
+
179
+ ```
180
+
181
+ <%= form_tag("/users/#{@user.id}/update", {multipart: true}) do %>
182
+
183
+ <ul>
184
+
185
+ <li>
186
+
187
+ <div class="col-1">User name</div>
188
+
189
+ <div class="col-2"><input size="40" name="name" maxlength=30 value="<%= @user.name %>"></div>
190
+
191
+ </li>
192
+
193
+ <li>
194
+
195
+ <div class="col-1">Profile picture</div>
196
+
197
+ <div class="col-2">
198
+
199
+ <input name="image" type="file" accept=".png, .jpg, .jpeg, .gif" id="file_photo" class="file_photo" value="<%= @user.image_name %>">
200
+
201
+ </div><br>
202
+
203
+ <div class="col-1"></div>
204
+
205
+ <div class="col-2 valid-note">*Please select a file when you need to change the current one.</div>
206
+
207
+ </li>
208
+
209
+ <li>
210
+
211
+ <div class="col-1">Cover picture</div>
212
+
213
+ <div class="col-2">
214
+
215
+ <input name="cover_image" type="file" accept=".png, .jpg, .jpeg, .gif" id="file_photo2" class="file_photo">
216
+
217
+ </div><br>
218
+
219
+ <div class="col-1"></div>
220
+
221
+ <div class="col-2 valid-note">*Please select a file when you need to change the current one.</div>
222
+
223
+ </li>
224
+
225
+ </li>
226
+
227
+ </ul>
228
+
229
+ <% end %>
230
+
231
+ ```

1

rails credentials:show のインデントを正しく修正致しました。

2021/12/01 05:49

投稿

punchan36
punchan36

スコア105

test CHANGED
File without changes
test CHANGED
@@ -86,9 +86,11 @@
86
86
 
87
87
  aws:
88
88
 
89
- access_key_id: AKIAZEMNWDXHF…(省略)
89
+  access_key_id: AKIAZEMNWDXHF…(省略)
90
90
 
91
- secret_access_key: zirfU8ftVfM1cbR…(省略)
91
+  secret_access_key: zirfU8ftVfM1cbR…(省略)
92
+
93
+
92
94
 
93
95
  secret_key_base: d6019fca51c34eba5cb6eb2a5d7027d7d60f…(省略)
94
96