質問編集履歴
3
_form.html.erbの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -372,6 +372,80 @@
|
|
372
372
|
|
373
373
|
```
|
374
374
|
|
375
|
+
|
376
|
+
|
377
|
+
```
|
378
|
+
|
379
|
+
#_form.html.erb
|
380
|
+
|
381
|
+
<%= form_with model: @profile, local: true do |f| %>
|
382
|
+
|
383
|
+
<div class="form-group">
|
384
|
+
|
385
|
+
<%= f.label :name, "ニックネーム" %>
|
386
|
+
|
387
|
+
<%= f.text_field :name %>
|
388
|
+
|
389
|
+
</div>
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
<div class="form-group">
|
394
|
+
|
395
|
+
<%= f.label :learning_history, "学習歴(年)" %>
|
396
|
+
|
397
|
+
<%= f.number_field :learning_history %>
|
398
|
+
|
399
|
+
</div>
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
<div class="form-group">
|
404
|
+
|
405
|
+
<%= f.label :purpose, "学習目的" %>
|
406
|
+
|
407
|
+
<%= f.text_field :purpose %>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
<div class="form-group">
|
414
|
+
|
415
|
+
<%= f.label :image, "プロフィール画像"%>
|
416
|
+
|
417
|
+
<%= f.file_field :images %><br>
|
418
|
+
|
419
|
+
</div>
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
<%# f.object = post %>
|
424
|
+
|
425
|
+
<% if f.object.image.attached? %>
|
426
|
+
|
427
|
+
<div class="image-preview">
|
428
|
+
|
429
|
+
<span>現在アップロードされている画像:</span>
|
430
|
+
|
431
|
+
<%= image_tag f.object.image %>
|
432
|
+
|
433
|
+
</div>
|
434
|
+
|
435
|
+
<% end %>
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
<div class="submit-block">
|
440
|
+
|
441
|
+
<%= f.submit 'Update Profile', class: "button" %>
|
442
|
+
|
443
|
+
</div>
|
444
|
+
|
445
|
+
<% end %>
|
446
|
+
|
447
|
+
```
|
448
|
+
|
375
449
|
### 詳細
|
376
450
|
|
377
451
|
画像を任意のものに変更しようとしても、
|
2
profile.rb、Profile_controller.rbの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -264,7 +264,113 @@
|
|
264
264
|
|
265
265
|
```
|
266
266
|
|
267
|
-
|
267
|
+
```
|
268
|
+
|
269
|
+
#Profile_controller.rb
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
class ProfilesController < ApplicationController
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
before_action :authenticate_user!
|
278
|
+
|
279
|
+
before_action :find_profile, only: [:show, :edit, :update]
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
def show
|
284
|
+
|
285
|
+
@profile = Profile.find(params[:id])
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
def new
|
292
|
+
|
293
|
+
return redirect_to edit_profile_path(current_user.profile) if current_user.profile.present?
|
294
|
+
|
295
|
+
@profile = Profile.new
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
def edit
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
def create
|
308
|
+
|
309
|
+
@profile = Profile.new(profile_params)
|
310
|
+
|
311
|
+
@profile.user = current_user
|
312
|
+
|
313
|
+
if @profile.save
|
314
|
+
|
315
|
+
redirect_to root_path, notice: "プロフィール情報の登録が完了しました"
|
316
|
+
|
317
|
+
else
|
318
|
+
|
319
|
+
render :new
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
def update
|
328
|
+
|
329
|
+
if @profile.update(profile_params)
|
330
|
+
|
331
|
+
redirect_to root_path, notice: "プロフィール情報の更新が完了しました"
|
332
|
+
|
333
|
+
else
|
334
|
+
|
335
|
+
render :edit
|
336
|
+
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
def destroy
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
private
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
def find_profile
|
354
|
+
|
355
|
+
@profile = Profile.find(params[:id])
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
def profile_params
|
362
|
+
|
363
|
+
params.require(:profile).permit(
|
364
|
+
|
365
|
+
:name, :learning_history, :purpose, :image
|
366
|
+
|
367
|
+
)
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
372
|
+
|
373
|
+
```
|
268
374
|
|
269
375
|
### 詳細
|
270
376
|
|
1
#profile.rbの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -240,7 +240,29 @@
|
|
240
240
|
|
241
241
|
|
242
242
|
|
243
|
-
|
243
|
+
```
|
244
|
+
|
245
|
+
#profile.rb
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
class Profile < ApplicationRecord
|
250
|
+
|
251
|
+
has_one_attached :image
|
252
|
+
|
253
|
+
belongs_to :user
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
validates :name, presence: true
|
258
|
+
|
259
|
+
validates :learning_history, presence: true
|
260
|
+
|
261
|
+
validates :purpose, presence: true
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
```
|
244
266
|
|
245
267
|
|
246
268
|
|