質問編集履歴
5
ソースコードを修正致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -636,7 +636,7 @@
|
|
636
636
|
|
637
637
|
```
|
638
638
|
|
639
|
-
schema.rb
|
639
|
+
schema.rbの一部分
|
640
640
|
|
641
641
|
|
642
642
|
|
4
ソースコードを修正致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,116 @@
|
|
26
26
|
|
27
27
|
@user = User.find(params[:id])
|
28
28
|
|
29
|
+
@skill = @user.skills.page(params[:page])
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
def new
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
```2
|
42
|
+
|
43
|
+
NoMethodError in Users#show
|
44
|
+
|
45
|
+
undefined method `title' for #<ActiveRecord::AssociationRelation []>
|
46
|
+
|
47
|
+
<div class="center jumbotron">
|
48
|
+
|
49
|
+
<div class="text-center">
|
50
|
+
|
51
|
+
<%= @skill.title %>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div class="center jumbotron">
|
58
|
+
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
### 該当のソースコード
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```Ruby
|
68
|
+
|
69
|
+
routes.rb
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Rails.application.routes.draw do
|
74
|
+
|
75
|
+
root to: 'toppages#index'
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
get 'login', to: 'sessions#new'
|
80
|
+
|
81
|
+
post 'login', to: 'sessions#create'
|
82
|
+
|
83
|
+
delete 'logout', to: 'sessions#destroy'
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
get 'signup', to: 'users#new'
|
88
|
+
|
89
|
+
resources :users, only: [:index, :show, :new, :create, :edit]
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
put 'users/:id/edit', to: 'users#edit'
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
put '/users/:id', to: 'users#update'
|
98
|
+
|
99
|
+
get 'users/:id/edit', to: 'users#edit'
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
resources :posts
|
104
|
+
|
105
|
+
resources :skills, only: [:create, :edit, :destroy]
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
users_controller.rb
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
class UsersController < ApplicationController
|
120
|
+
|
121
|
+
before_action :require_user_logged_in, only: [:index, :show]
|
122
|
+
|
123
|
+
before_action :correct_user, only: [:edit]
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def index
|
128
|
+
|
129
|
+
@users = User.order(id: :desc).page(params[:page]).per(50)
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
def show
|
136
|
+
|
137
|
+
@user = User.find(params[:id])
|
138
|
+
|
29
139
|
@skills = @user.skills.page(params[:page])
|
30
140
|
|
31
141
|
end
|
@@ -34,20 +144,234 @@
|
|
34
144
|
|
35
145
|
def new
|
36
146
|
|
37
|
-
|
147
|
+
@user = User.new
|
148
|
+
|
38
|
-
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
def create
|
154
|
+
|
155
|
+
@user = User.new(user_params)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
if @user.save
|
160
|
+
|
161
|
+
flash[:success] = 'ユーザを登録しました。'
|
162
|
+
|
163
|
+
redirect_to @user
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
168
|
+
|
169
|
+
render :new
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
def edit
|
178
|
+
|
179
|
+
@user = User.find(params[:id])
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
def update
|
186
|
+
|
187
|
+
@user = User.find(params[:id])
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
if @user.update(user_params)
|
192
|
+
|
193
|
+
flash[:success] = 'プロフィールを変更しました。'
|
194
|
+
|
195
|
+
redirect_to @user
|
196
|
+
|
197
|
+
else
|
198
|
+
|
199
|
+
flash.now[:danger] = 'プロフィールが変更できませんでした。'
|
200
|
+
|
201
|
+
render :edit
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
private
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
def user_params
|
214
|
+
|
215
|
+
params.require(:user).permit(:name, :email, :password, :password_confirmation, :profession, :first_name, :last_name, :profile,)
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
def correct_user
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
39
|
-
```
|
227
|
+
```
|
40
|
-
|
228
|
+
|
41
|
-
```
|
229
|
+
```
|
230
|
+
|
42
|
-
|
231
|
+
skills_controller.rb
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
class SkillsController < ApplicationController
|
236
|
+
|
43
|
-
|
237
|
+
before_action :require_user_logged_in
|
238
|
+
|
44
|
-
|
239
|
+
before_action :correct_user, only: [:destroy]
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
def create
|
244
|
+
|
245
|
+
@skills = current_user.skills.build(skill_params)
|
246
|
+
|
247
|
+
if @skill.save
|
248
|
+
|
249
|
+
flash[:success] = "スキルを登録しました。"
|
250
|
+
|
251
|
+
redirect_to root_url
|
252
|
+
|
253
|
+
else
|
254
|
+
|
255
|
+
@skills = current_user.feed_skills.order(id: :desc).page(params[:page])
|
256
|
+
|
257
|
+
flash.now[:danger] = "スキルの登録に失敗しました。"
|
258
|
+
|
259
|
+
render "users/edit"
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
def edit
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
def destroy
|
274
|
+
|
275
|
+
@skill.destroy
|
276
|
+
|
277
|
+
flash[:success] = "スキルを削除しました。"
|
278
|
+
|
279
|
+
redirect_back(fallback_location: root_path)
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
```
|
288
|
+
|
289
|
+
users/show.html.erb
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
<div class="row">
|
294
|
+
|
295
|
+
<aside class="col-sm-12">
|
296
|
+
|
297
|
+
<div class="text-left">
|
298
|
+
|
45
|
-
|
299
|
+
<%= link_to 'プロフィール変更', edit_user_path(@user) %>
|
300
|
+
|
301
|
+
</div>
|
302
|
+
|
303
|
+
</aside>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
<aside class="col-sm-12">
|
308
|
+
|
309
|
+
<table class="table table-bordered">
|
310
|
+
|
311
|
+
<tr>
|
312
|
+
|
313
|
+
<th>職業</th>
|
314
|
+
|
315
|
+
<td><%= @user.profession %></td>
|
316
|
+
|
317
|
+
</tr>
|
318
|
+
|
319
|
+
<tr>
|
320
|
+
|
321
|
+
<th>名前</th>
|
322
|
+
|
323
|
+
<td><%= @user.last_name %> <%= @user.first_name %></td>
|
324
|
+
|
325
|
+
</tr>
|
326
|
+
|
327
|
+
<tr>
|
328
|
+
|
329
|
+
<th>自己紹介</th>
|
330
|
+
|
331
|
+
<td><%= @user.profile %></td>
|
332
|
+
|
333
|
+
</tr>
|
334
|
+
|
335
|
+
</table>
|
336
|
+
|
337
|
+
</aside>
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
<aside class="col-sm-12">
|
46
342
|
|
47
343
|
<div class="center jumbotron">
|
48
344
|
|
49
345
|
<div class="text-center">
|
50
346
|
|
347
|
+
<h2>SKILL</h2>
|
348
|
+
|
349
|
+
</div>
|
350
|
+
|
351
|
+
</div>
|
352
|
+
|
353
|
+
</aside>
|
354
|
+
|
355
|
+
<aside class="col-sm-6">
|
356
|
+
|
357
|
+
<div class="center jumbotron">
|
358
|
+
|
359
|
+
<div class="text-center">
|
360
|
+
|
361
|
+
<img class="rounded img-fluid" src="<%= gravatar_url(@user, { size: 250 }) %>" alt="">
|
362
|
+
|
363
|
+
</div>
|
364
|
+
|
365
|
+
</div>
|
366
|
+
|
367
|
+
</aside>
|
368
|
+
|
369
|
+
<aside class="col-sm-6">
|
370
|
+
|
371
|
+
<div class="center jumbotron">
|
372
|
+
|
373
|
+
<div class="text-center">
|
374
|
+
|
51
375
|
<%= @skill.title %>
|
52
376
|
|
53
377
|
</div>
|
@@ -56,584 +380,344 @@
|
|
56
380
|
|
57
381
|
<div class="center jumbotron">
|
58
382
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
reso
|
104
|
-
|
105
|
-
|
383
|
+
<div class="text-center">
|
384
|
+
|
385
|
+
<%= @skill.description %>
|
386
|
+
|
387
|
+
</div>
|
388
|
+
|
389
|
+
</div>
|
390
|
+
|
391
|
+
</aside>
|
392
|
+
|
393
|
+
</div>
|
394
|
+
|
395
|
+
```
|
396
|
+
|
397
|
+
```
|
398
|
+
|
399
|
+
users/edit.html.erb
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
<div class="text-center">
|
404
|
+
|
405
|
+
<h1>プロフィール変更画面</h1>
|
406
|
+
|
407
|
+
</div>
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
<div class="row">
|
412
|
+
|
413
|
+
<div class="col-sm-6 offset-sm-3">
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
418
|
+
|
419
|
+
<%= render 'layouts/error_messages', model: f.object %>
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
<div class="form-group">
|
424
|
+
|
425
|
+
<%= f.label :profession, 'Profession' %>
|
426
|
+
|
427
|
+
<%= f.text_field :profession, class: 'form-control' %>
|
428
|
+
|
429
|
+
</div>
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
<div class="form-group">
|
434
|
+
|
435
|
+
<%= f.label :first_name, 'First Name' %>
|
436
|
+
|
437
|
+
<%= f.text_field :first_name, class: 'form-control' %>
|
438
|
+
|
439
|
+
</div>
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
<div class="form-group">
|
444
|
+
|
445
|
+
<%= f.label :last_name, 'Last Name' %>
|
446
|
+
|
447
|
+
<%= f.text_field :last_name, class: 'form-control' %>
|
448
|
+
|
449
|
+
</div>
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
<div class="form-group">
|
454
|
+
|
455
|
+
<%= f.label :profile, 'Profile' %>
|
456
|
+
|
457
|
+
<%= f.text_field :profile, class: 'form-control' %>
|
458
|
+
|
459
|
+
</div>
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
<div class="text-left">
|
464
|
+
|
465
|
+
<h3>Security</h3>
|
466
|
+
|
467
|
+
</div>
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
<div class="form-group">
|
472
|
+
|
473
|
+
<%= f.label :email, 'Email' %>
|
474
|
+
|
475
|
+
<%= f.email_field :email, class: 'form-control' %>
|
476
|
+
|
477
|
+
</div>
|
478
|
+
|
479
|
+
<div class="form-group">
|
480
|
+
|
481
|
+
<%= f.label :password, 'Password' %>
|
482
|
+
|
483
|
+
<%= f.password_field :password, class: 'form-control' %>
|
484
|
+
|
485
|
+
</div>
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
<div class="text-left">
|
494
|
+
|
495
|
+
<h3>SKILL</h3>
|
496
|
+
|
497
|
+
</div>
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
<%= render 'skills/edit', skills: @skill %>
|
502
|
+
|
503
|
+
<% end %>
|
504
|
+
|
505
|
+
</div>
|
506
|
+
|
507
|
+
</div>
|
508
|
+
|
509
|
+
```
|
510
|
+
|
511
|
+
```
|
512
|
+
|
513
|
+
skills/_edit.html.erb
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
518
|
+
|
519
|
+
<%= render 'layouts/error_messages', model: f.object %>
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
<div class="form-group">
|
524
|
+
|
525
|
+
<%= f.label :title, 'Skill Title' %>
|
526
|
+
|
527
|
+
<%= f.text_field :title, class: 'form-control' %>
|
528
|
+
|
529
|
+
</div>
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
<div class="form-group">
|
534
|
+
|
535
|
+
<%= f.label :description, 'Skill Descriotion' %>
|
536
|
+
|
537
|
+
<%= f.text_field :description, class: 'form-control' %>
|
538
|
+
|
539
|
+
</div>
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
544
|
+
|
545
|
+
<% end %>
|
546
|
+
|
547
|
+
```
|
548
|
+
|
549
|
+
```
|
550
|
+
|
551
|
+
user.rb
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
class User < ApplicationRecord
|
556
|
+
|
557
|
+
validates :name, presence: true, length: { maximum: 50 }
|
558
|
+
|
559
|
+
validates :email, presence: true, length: { maximum: 255 },
|
560
|
+
|
561
|
+
format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i },
|
562
|
+
|
563
|
+
uniqueness: { case_sensitive: false }
|
564
|
+
|
565
|
+
validates :password, allow_blank: true, length: { maximum: 20 }
|
566
|
+
|
567
|
+
validates :profession, allow_blank: true, length: { maximum: 20 }
|
568
|
+
|
569
|
+
validates :first_name, allow_blank: true, length: { maximum: 10 }
|
570
|
+
|
571
|
+
validates :last_name, allow_blank: true, length: { maximum: 10 }
|
572
|
+
|
573
|
+
validates :profile, allow_blank: true, length: { maximum: 200 }
|
574
|
+
|
575
|
+
has_secure_password
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
has_many :posts
|
580
|
+
|
581
|
+
has_many :skills
|
106
582
|
|
107
583
|
end
|
108
584
|
|
109
|
-
|
110
|
-
|
111
|
-
```
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
e
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
de
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
def create
|
154
|
-
|
155
|
-
@user = User.new(user_params)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
if @user.save
|
160
|
-
|
161
|
-
flash[:success] = 'ユーザを登録しました。'
|
162
|
-
|
163
|
-
redirect_to @user
|
164
|
-
|
165
|
-
else
|
166
|
-
|
167
|
-
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
168
|
-
|
169
|
-
render :new
|
585
|
+
```
|
586
|
+
|
587
|
+
```
|
588
|
+
|
589
|
+
skill.rb
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
class Skill < ApplicationRecord
|
594
|
+
|
595
|
+
belongs_to :user
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
validates :title, length: { maximum: 10 }
|
600
|
+
|
601
|
+
validates :description, length: { maximum: 150 }
|
602
|
+
|
603
|
+
end
|
604
|
+
|
605
|
+
```
|
606
|
+
|
607
|
+
```
|
608
|
+
|
609
|
+
20201026001900_create_skills
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
class CreateSkills < ActiveRecord::Migration[5.2]
|
614
|
+
|
615
|
+
def change
|
616
|
+
|
617
|
+
create_table :skills do |t|
|
618
|
+
|
619
|
+
t.string :title
|
620
|
+
|
621
|
+
t.text :description
|
622
|
+
|
623
|
+
t.references :user, foreign_key: true
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
t.timestamps
|
170
628
|
|
171
629
|
end
|
172
630
|
|
173
631
|
end
|
174
632
|
|
175
|
-
|
176
|
-
|
177
|
-
def edit
|
178
|
-
|
179
|
-
@user = User.find(params[:id])
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
def update
|
186
|
-
|
187
|
-
@user = User.find(params[:id])
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
if @user.update(user_params)
|
192
|
-
|
193
|
-
flash[:success] = 'プロフィールを変更しました。'
|
194
|
-
|
195
|
-
redirect_to @user
|
196
|
-
|
197
|
-
else
|
198
|
-
|
199
|
-
flash.now[:danger] = 'プロフィールが変更できませんでした。'
|
200
|
-
|
201
|
-
render :edit
|
202
|
-
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
private
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
def user_params
|
214
|
-
|
215
|
-
params.require(:user).permit(:name, :email, :password, :password_confirmation, :profession, :first_name, :last_name, :profile,)
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
def correct_user
|
222
|
-
|
223
|
-
end
|
224
|
-
|
225
633
|
end
|
226
634
|
|
227
635
|
```
|
228
636
|
|
229
637
|
```
|
230
638
|
|
231
|
-
s
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
c
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
i
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
e
|
262
|
-
|
263
|
-
en
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
de
|
268
|
-
|
269
|
-
end
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
en
|
639
|
+
schema.rb
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
ActiveRecord::Schema.define(version: 2020_10_31_081638) do
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
create_table "posts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
648
|
+
|
649
|
+
t.string "image"
|
650
|
+
|
651
|
+
t.bigint "user_id"
|
652
|
+
|
653
|
+
t.datetime "created_at", null: false
|
654
|
+
|
655
|
+
t.datetime "updated_at", null: false
|
656
|
+
|
657
|
+
t.index ["user_id"], name: "index_posts_on_user_id"
|
658
|
+
|
659
|
+
end
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
create_table "skills", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
664
|
+
|
665
|
+
t.string "title"
|
666
|
+
|
667
|
+
t.text "description"
|
668
|
+
|
669
|
+
t.bigint "user_id"
|
670
|
+
|
671
|
+
t.datetime "created_at", null: false
|
672
|
+
|
673
|
+
t.datetime "updated_at", null: false
|
674
|
+
|
675
|
+
t.index ["user_id"], name: "index_skills_on_user_id"
|
676
|
+
|
677
|
+
end
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
682
|
+
|
683
|
+
t.string "name"
|
684
|
+
|
685
|
+
t.string "email"
|
686
|
+
|
687
|
+
t.string "password_digest"
|
688
|
+
|
689
|
+
t.string "profession"
|
690
|
+
|
691
|
+
t.string "first_name"
|
692
|
+
|
693
|
+
t.string "last_name"
|
694
|
+
|
695
|
+
t.text "profile"
|
696
|
+
|
697
|
+
t.timestamp "icon"
|
698
|
+
|
699
|
+
t.string "new_email"
|
700
|
+
|
701
|
+
t.string "new_password"
|
702
|
+
|
703
|
+
t.string "image"
|
704
|
+
|
705
|
+
t.datetime "created_at", null: false
|
706
|
+
|
707
|
+
t.datetime "updated_at", null: false
|
708
|
+
|
709
|
+
end
|
710
|
+
|
711
|
+
|
712
|
+
|
713
|
+
add_foreign_key "posts", "users"
|
714
|
+
|
715
|
+
add_foreign_key "skills", "users"
|
282
716
|
|
283
717
|
end
|
284
718
|
|
285
719
|
```
|
286
720
|
|
287
|
-
```
|
288
|
-
|
289
|
-
users/show.html.erb
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
<div class="row">
|
294
|
-
|
295
|
-
<aside class="col-sm-12">
|
296
|
-
|
297
|
-
<div class="text-left">
|
298
|
-
|
299
|
-
<%= link_to 'プロフィール変更', edit_user_path(@user) %>
|
300
|
-
|
301
|
-
</div>
|
302
|
-
|
303
|
-
</aside>
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
<aside class="col-sm-12">
|
308
|
-
|
309
|
-
<table class="table table-bordered">
|
310
|
-
|
311
|
-
<tr>
|
312
|
-
|
313
|
-
<th>職業</th>
|
314
|
-
|
315
|
-
<td><%= @user.profession %></td>
|
316
|
-
|
317
|
-
</tr>
|
318
|
-
|
319
|
-
<tr>
|
320
|
-
|
321
|
-
<th>名前</th>
|
322
|
-
|
323
|
-
<td><%= @user.last_name %> <%= @user.first_name %></td>
|
324
|
-
|
325
|
-
</tr>
|
326
|
-
|
327
|
-
<tr>
|
328
|
-
|
329
|
-
<th>自己紹介</th>
|
330
|
-
|
331
|
-
<td><%= @user.profile %></td>
|
332
|
-
|
333
|
-
</tr>
|
334
|
-
|
335
|
-
</table>
|
336
|
-
|
337
|
-
</aside>
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
<aside class="col-sm-12">
|
342
|
-
|
343
|
-
<div class="center jumbotron">
|
344
|
-
|
345
|
-
<div class="text-center">
|
346
|
-
|
347
|
-
<h2>SKILL</h2>
|
348
|
-
|
349
|
-
</div>
|
350
|
-
|
351
|
-
</div>
|
352
|
-
|
353
|
-
</aside>
|
354
|
-
|
355
|
-
<aside class="col-sm-6">
|
356
|
-
|
357
|
-
<div class="center jumbotron">
|
358
|
-
|
359
|
-
<div class="text-center">
|
360
|
-
|
361
|
-
<img class="rounded img-fluid" src="<%= gravatar_url(@user, { size: 250 }) %>" alt="">
|
362
|
-
|
363
|
-
</div>
|
364
|
-
|
365
|
-
</div>
|
366
|
-
|
367
|
-
</aside>
|
368
|
-
|
369
|
-
<aside class="col-sm-6">
|
370
|
-
|
371
|
-
<div class="center jumbotron">
|
372
|
-
|
373
|
-
<div class="text-center">
|
374
|
-
|
375
|
-
<%= @skill.title %>
|
376
|
-
|
377
|
-
</div>
|
378
|
-
|
379
|
-
</div>
|
380
|
-
|
381
|
-
<div class="center jumbotron">
|
382
|
-
|
383
|
-
<div class="text-center">
|
384
|
-
|
385
|
-
<%= @skill.description %>
|
386
|
-
|
387
|
-
</div>
|
388
|
-
|
389
|
-
</div>
|
390
|
-
|
391
|
-
</aside>
|
392
|
-
|
393
|
-
</div>
|
394
|
-
|
395
|
-
```
|
396
|
-
|
397
|
-
```
|
398
|
-
|
399
|
-
users/edit.html.erb
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
<div class="text-center">
|
404
|
-
|
405
|
-
<h1>プロフィール変更画面</h1>
|
406
|
-
|
407
|
-
</div>
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
<div class="row">
|
412
|
-
|
413
|
-
<div class="col-sm-6 offset-sm-3">
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
418
|
-
|
419
|
-
<%= render 'layouts/error_messages', model: f.object %>
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
<div class="form-group">
|
424
|
-
|
425
|
-
<%= f.label :profession, 'Profession' %>
|
426
|
-
|
427
|
-
<%= f.text_field :profession, class: 'form-control' %>
|
428
|
-
|
429
|
-
</div>
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
<div class="form-group">
|
434
|
-
|
435
|
-
<%= f.label :first_name, 'First Name' %>
|
436
|
-
|
437
|
-
<%= f.text_field :first_name, class: 'form-control' %>
|
438
|
-
|
439
|
-
</div>
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
<div class="form-group">
|
444
|
-
|
445
|
-
<%= f.label :last_name, 'Last Name' %>
|
446
|
-
|
447
|
-
<%= f.text_field :last_name, class: 'form-control' %>
|
448
|
-
|
449
|
-
</div>
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
<div class="form-group">
|
454
|
-
|
455
|
-
<%= f.label :profile, 'Profile' %>
|
456
|
-
|
457
|
-
<%= f.text_field :profile, class: 'form-control' %>
|
458
|
-
|
459
|
-
</div>
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
<div class="text-left">
|
464
|
-
|
465
|
-
<h3>Security</h3>
|
466
|
-
|
467
|
-
</div>
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
<div class="form-group">
|
472
|
-
|
473
|
-
<%= f.label :email, 'Email' %>
|
474
|
-
|
475
|
-
<%= f.email_field :email, class: 'form-control' %>
|
476
|
-
|
477
|
-
</div>
|
478
|
-
|
479
|
-
<div class="form-group">
|
480
|
-
|
481
|
-
<%= f.label :password, 'Password' %>
|
482
|
-
|
483
|
-
<%= f.password_field :password, class: 'form-control' %>
|
484
|
-
|
485
|
-
</div>
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
<div class="text-left">
|
494
|
-
|
495
|
-
<h3>SKILL</h3>
|
496
|
-
|
497
|
-
</div>
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
<%= render 'skills/edit', skills: @skill %>
|
502
|
-
|
503
|
-
<% end %>
|
504
|
-
|
505
|
-
</div>
|
506
|
-
|
507
|
-
</div>
|
508
|
-
|
509
|
-
```
|
510
|
-
|
511
|
-
```
|
512
|
-
|
513
|
-
skills/_edit.html.erb
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
518
|
-
|
519
|
-
<%= render 'layouts/error_messages', model: f.object %>
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
<div class="form-group">
|
524
|
-
|
525
|
-
<%= f.label :title, 'Skill Title' %>
|
526
|
-
|
527
|
-
<%= f.text_field :title, class: 'form-control' %>
|
528
|
-
|
529
|
-
</div>
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
<div class="form-group">
|
534
|
-
|
535
|
-
<%= f.label :description, 'Skill Descriotion' %>
|
536
|
-
|
537
|
-
<%= f.text_field :description, class: 'form-control' %>
|
538
|
-
|
539
|
-
</div>
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
544
|
-
|
545
|
-
<% end %>
|
546
|
-
|
547
|
-
```
|
548
|
-
|
549
|
-
```
|
550
|
-
|
551
|
-
user.rb
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
class User < ApplicationRecord
|
556
|
-
|
557
|
-
validates :name, presence: true, length: { maximum: 50 }
|
558
|
-
|
559
|
-
validates :email, presence: true, length: { maximum: 255 },
|
560
|
-
|
561
|
-
format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i },
|
562
|
-
|
563
|
-
uniqueness: { case_sensitive: false }
|
564
|
-
|
565
|
-
validates :password, allow_blank: true, length: { maximum: 20 }
|
566
|
-
|
567
|
-
validates :profession, allow_blank: true, length: { maximum: 20 }
|
568
|
-
|
569
|
-
validates :first_name, allow_blank: true, length: { maximum: 10 }
|
570
|
-
|
571
|
-
validates :last_name, allow_blank: true, length: { maximum: 10 }
|
572
|
-
|
573
|
-
validates :profile, allow_blank: true, length: { maximum: 200 }
|
574
|
-
|
575
|
-
has_secure_password
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
has_many :posts
|
580
|
-
|
581
|
-
has_many :skills
|
582
|
-
|
583
|
-
end
|
584
|
-
|
585
|
-
```
|
586
|
-
|
587
|
-
```
|
588
|
-
|
589
|
-
skill.rb
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
class Skill < ApplicationRecord
|
594
|
-
|
595
|
-
belongs_to :user
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
validates :title, length: { maximum: 10 }
|
600
|
-
|
601
|
-
validates :description, length: { maximum: 150 }
|
602
|
-
|
603
|
-
end
|
604
|
-
|
605
|
-
```
|
606
|
-
|
607
|
-
```
|
608
|
-
|
609
|
-
20201026001900_create_skills
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
class CreateSkills < ActiveRecord::Migration[5.2]
|
614
|
-
|
615
|
-
def change
|
616
|
-
|
617
|
-
create_table :skills do |t|
|
618
|
-
|
619
|
-
t.string :title
|
620
|
-
|
621
|
-
t.text :description
|
622
|
-
|
623
|
-
t.references :user, foreign_key: true
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
t.timestamps
|
628
|
-
|
629
|
-
end
|
630
|
-
|
631
|
-
end
|
632
|
-
|
633
|
-
end
|
634
|
-
|
635
|
-
```
|
636
|
-
|
637
721
|
|
638
722
|
|
639
723
|
### 試したこと
|
3
実現したいこと・エラーメッセージ・ソースコードを修正致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
###①ログイン後、ActiveRecord::StatementInvalid in UsersController#showが表示される。
|
10
10
|
|
11
|
+
###②ユーザ詳細画面にてNoMethodError in Users#showが表示される。
|
12
|
+
|
11
13
|
|
12
14
|
|
13
15
|
### 発生している問題・エラーメッセージ
|
@@ -36,6 +38,26 @@
|
|
36
38
|
|
37
39
|
```
|
38
40
|
|
41
|
+
```2
|
42
|
+
|
43
|
+
NoMethodError in Users#show
|
44
|
+
|
45
|
+
undefined method `title' for #<ActiveRecord::AssociationRelation []>
|
46
|
+
|
47
|
+
<div class="center jumbotron">
|
48
|
+
|
49
|
+
<div class="text-center">
|
50
|
+
|
51
|
+
<%= @skill.title %>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div class="center jumbotron">
|
58
|
+
|
59
|
+
```
|
60
|
+
|
39
61
|
|
40
62
|
|
41
63
|
### 該当のソースコード
|
@@ -350,7 +372,7 @@
|
|
350
372
|
|
351
373
|
<div class="text-center">
|
352
374
|
|
353
|
-
<%= @skill.
|
375
|
+
<%= @skill.title %>
|
354
376
|
|
355
377
|
</div>
|
356
378
|
|
@@ -360,7 +382,7 @@
|
|
360
382
|
|
361
383
|
<div class="text-center">
|
362
384
|
|
363
|
-
<%= @skill.
|
385
|
+
<%= @skill.description %>
|
364
386
|
|
365
387
|
</div>
|
366
388
|
|
@@ -476,7 +498,7 @@
|
|
476
498
|
|
477
499
|
|
478
500
|
|
479
|
-
<%= render 'skills/edit', skills: @skill
|
501
|
+
<%= render 'skills/edit', skills: @skill %>
|
480
502
|
|
481
503
|
<% end %>
|
482
504
|
|
@@ -500,9 +522,9 @@
|
|
500
522
|
|
501
523
|
<div class="form-group">
|
502
524
|
|
503
|
-
<%= f.label :
|
525
|
+
<%= f.label :title, 'Skill Title' %>
|
504
|
-
|
526
|
+
|
505
|
-
<%= f.text_field :
|
527
|
+
<%= f.text_field :title, class: 'form-control' %>
|
506
528
|
|
507
529
|
</div>
|
508
530
|
|
@@ -510,9 +532,9 @@
|
|
510
532
|
|
511
533
|
<div class="form-group">
|
512
534
|
|
513
|
-
<%= f.label :
|
535
|
+
<%= f.label :description, 'Skill Descriotion' %>
|
514
|
-
|
536
|
+
|
515
|
-
<%= f.text_field :
|
537
|
+
<%= f.text_field :description, class: 'form-control' %>
|
516
538
|
|
517
539
|
</div>
|
518
540
|
|
@@ -524,6 +546,94 @@
|
|
524
546
|
|
525
547
|
```
|
526
548
|
|
549
|
+
```
|
550
|
+
|
551
|
+
user.rb
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
class User < ApplicationRecord
|
556
|
+
|
557
|
+
validates :name, presence: true, length: { maximum: 50 }
|
558
|
+
|
559
|
+
validates :email, presence: true, length: { maximum: 255 },
|
560
|
+
|
561
|
+
format: { with: /\A[\w+\-.]+@[a-z\d\-.]+.[a-z]+\z/i },
|
562
|
+
|
563
|
+
uniqueness: { case_sensitive: false }
|
564
|
+
|
565
|
+
validates :password, allow_blank: true, length: { maximum: 20 }
|
566
|
+
|
567
|
+
validates :profession, allow_blank: true, length: { maximum: 20 }
|
568
|
+
|
569
|
+
validates :first_name, allow_blank: true, length: { maximum: 10 }
|
570
|
+
|
571
|
+
validates :last_name, allow_blank: true, length: { maximum: 10 }
|
572
|
+
|
573
|
+
validates :profile, allow_blank: true, length: { maximum: 200 }
|
574
|
+
|
575
|
+
has_secure_password
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
has_many :posts
|
580
|
+
|
581
|
+
has_many :skills
|
582
|
+
|
583
|
+
end
|
584
|
+
|
585
|
+
```
|
586
|
+
|
587
|
+
```
|
588
|
+
|
589
|
+
skill.rb
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
class Skill < ApplicationRecord
|
594
|
+
|
595
|
+
belongs_to :user
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
validates :title, length: { maximum: 10 }
|
600
|
+
|
601
|
+
validates :description, length: { maximum: 150 }
|
602
|
+
|
603
|
+
end
|
604
|
+
|
605
|
+
```
|
606
|
+
|
607
|
+
```
|
608
|
+
|
609
|
+
20201026001900_create_skills
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
class CreateSkills < ActiveRecord::Migration[5.2]
|
614
|
+
|
615
|
+
def change
|
616
|
+
|
617
|
+
create_table :skills do |t|
|
618
|
+
|
619
|
+
t.string :title
|
620
|
+
|
621
|
+
t.text :description
|
622
|
+
|
623
|
+
t.references :user, foreign_key: true
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
t.timestamps
|
628
|
+
|
629
|
+
end
|
630
|
+
|
631
|
+
end
|
632
|
+
|
633
|
+
end
|
634
|
+
|
635
|
+
```
|
636
|
+
|
527
637
|
|
528
638
|
|
529
639
|
### 試したこと
|
2
前提・実現したいことを編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
###①
|
9
|
+
###①ログイン後、ActiveRecord::StatementInvalid in UsersController#showが表示される。
|
10
10
|
|
11
11
|
|
12
12
|
|
1
エラーメッセージ・ソースコードを追記致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,16 +16,340 @@
|
|
16
16
|
|
17
17
|
```1
|
18
18
|
|
19
|
-
|
19
|
+
ActiveRecord::StatementInvalid in UsersController#show
|
20
|
-
|
20
|
+
|
21
|
-
|
21
|
+
Mysql2::Error: Unknown column 'users.user_id' in 'where clause': SELECT `users`.* FROM `users` WHERE `users`.`user_id` = 1 LIMIT 1
|
22
|
+
|
22
|
-
|
23
|
+
def show
|
24
|
+
|
25
|
+
@user = User.find(params[:id])
|
26
|
+
|
27
|
+
@skills = @user.skills.page(params[:page])
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
def new
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
### 該当のソースコード
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```Ruby
|
46
|
+
|
47
|
+
routes.rb
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
Rails.application.routes.draw do
|
52
|
+
|
53
|
+
root to: 'toppages#index'
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
get 'login', to: 'sessions#new'
|
58
|
+
|
59
|
+
post 'login', to: 'sessions#create'
|
60
|
+
|
61
|
+
delete 'logout', to: 'sessions#destroy'
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
get 'signup', to: 'users#new'
|
66
|
+
|
67
|
+
resources :users, only: [:index, :show, :new, :create, :edit]
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
put 'users/:id/edit', to: 'users#edit'
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
put '/users/:id', to: 'users#update'
|
76
|
+
|
77
|
+
get 'users/:id/edit', to: 'users#edit'
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
resources :posts
|
82
|
+
|
83
|
+
resources :skills, only: [:create, :edit, :destroy]
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
users_controller.rb
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
class UsersController < ApplicationController
|
98
|
+
|
99
|
+
before_action :require_user_logged_in, only: [:index, :show]
|
100
|
+
|
23
|
-
|
101
|
+
before_action :correct_user, only: [:edit]
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
def index
|
106
|
+
|
107
|
+
@users = User.order(id: :desc).page(params[:page]).per(50)
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
def show
|
114
|
+
|
115
|
+
@user = User.find(params[:id])
|
116
|
+
|
117
|
+
@skills = @user.skills.page(params[:page])
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
def new
|
124
|
+
|
125
|
+
@user = User.new
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
def create
|
132
|
+
|
133
|
+
@user = User.new(user_params)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
if @user.save
|
138
|
+
|
139
|
+
flash[:success] = 'ユーザを登録しました。'
|
140
|
+
|
141
|
+
redirect_to @user
|
142
|
+
|
143
|
+
else
|
144
|
+
|
145
|
+
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
146
|
+
|
147
|
+
render :new
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
def edit
|
156
|
+
|
157
|
+
@user = User.find(params[:id])
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
def update
|
164
|
+
|
165
|
+
@user = User.find(params[:id])
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
if @user.update(user_params)
|
170
|
+
|
171
|
+
flash[:success] = 'プロフィールを変更しました。'
|
172
|
+
|
173
|
+
redirect_to @user
|
174
|
+
|
175
|
+
else
|
176
|
+
|
177
|
+
flash.now[:danger] = 'プロフィールが変更できませんでした。'
|
178
|
+
|
179
|
+
render :edit
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
private
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
def user_params
|
192
|
+
|
193
|
+
params.require(:user).permit(:name, :email, :password, :password_confirmation, :profession, :first_name, :last_name, :profile,)
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
def correct_user
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
skills_controller.rb
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
class SkillsController < ApplicationController
|
214
|
+
|
215
|
+
before_action :require_user_logged_in
|
216
|
+
|
217
|
+
before_action :correct_user, only: [:destroy]
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
def create
|
222
|
+
|
223
|
+
@skills = current_user.skills.build(skill_params)
|
224
|
+
|
225
|
+
if @skill.save
|
226
|
+
|
227
|
+
flash[:success] = "スキルを登録しました。"
|
228
|
+
|
229
|
+
redirect_to root_url
|
230
|
+
|
231
|
+
else
|
232
|
+
|
233
|
+
@skills = current_user.feed_skills.order(id: :desc).page(params[:page])
|
234
|
+
|
235
|
+
flash.now[:danger] = "スキルの登録に失敗しました。"
|
236
|
+
|
237
|
+
render "users/edit"
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
def edit
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
def destroy
|
252
|
+
|
253
|
+
@skill.destroy
|
254
|
+
|
255
|
+
flash[:success] = "スキルを削除しました。"
|
256
|
+
|
257
|
+
redirect_back(fallback_location: root_path)
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
```
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
users/show.html.erb
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
<div class="row">
|
272
|
+
|
273
|
+
<aside class="col-sm-12">
|
274
|
+
|
275
|
+
<div class="text-left">
|
276
|
+
|
277
|
+
<%= link_to 'プロフィール変更', edit_user_path(@user) %>
|
278
|
+
|
279
|
+
</div>
|
280
|
+
|
281
|
+
</aside>
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
<aside class="col-sm-12">
|
286
|
+
|
287
|
+
<table class="table table-bordered">
|
288
|
+
|
289
|
+
<tr>
|
290
|
+
|
291
|
+
<th>職業</th>
|
292
|
+
|
293
|
+
<td><%= @user.profession %></td>
|
294
|
+
|
295
|
+
</tr>
|
296
|
+
|
297
|
+
<tr>
|
298
|
+
|
299
|
+
<th>名前</th>
|
300
|
+
|
301
|
+
<td><%= @user.last_name %> <%= @user.first_name %></td>
|
302
|
+
|
303
|
+
</tr>
|
304
|
+
|
305
|
+
<tr>
|
306
|
+
|
307
|
+
<th>自己紹介</th>
|
308
|
+
|
309
|
+
<td><%= @user.profile %></td>
|
310
|
+
|
311
|
+
</tr>
|
312
|
+
|
313
|
+
</table>
|
314
|
+
|
315
|
+
</aside>
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<aside class="col-sm-12">
|
24
320
|
|
25
321
|
<div class="center jumbotron">
|
26
322
|
|
27
323
|
<div class="text-center">
|
28
324
|
|
325
|
+
<h2>SKILL</h2>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
</div>
|
330
|
+
|
331
|
+
</aside>
|
332
|
+
|
333
|
+
<aside class="col-sm-6">
|
334
|
+
|
335
|
+
<div class="center jumbotron">
|
336
|
+
|
337
|
+
<div class="text-center">
|
338
|
+
|
339
|
+
<img class="rounded img-fluid" src="<%= gravatar_url(@user, { size: 250 }) %>" alt="">
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
</div>
|
344
|
+
|
345
|
+
</aside>
|
346
|
+
|
347
|
+
<aside class="col-sm-6">
|
348
|
+
|
349
|
+
<div class="center jumbotron">
|
350
|
+
|
351
|
+
<div class="text-center">
|
352
|
+
|
29
353
|
<%= @skill.skill_title %>
|
30
354
|
|
31
355
|
</div>
|
@@ -34,283 +358,129 @@
|
|
34
358
|
|
35
359
|
<div class="center jumbotron">
|
36
360
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
```
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
post 'login', to: 'sessions#create'
|
64
|
-
|
65
|
-
delete 'logout', to: 'sessions#destroy'
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
get 'signup', to: 'users#new'
|
70
|
-
|
71
|
-
resources :users, only: [:index, :show, :new, :create, :edit]
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
put 'users/:id/edit', to: 'users#edit'
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
put '/users/:id', to: 'users#update'
|
80
|
-
|
81
|
-
get 'users/:id/edit', to: 'users#edit'
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
resources :posts
|
86
|
-
|
87
|
-
resources :skills, only: [:create, :edit, :destroy]
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
```
|
94
|
-
|
95
|
-
```
|
96
|
-
|
97
|
-
users_controller.rb
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
class UsersController < ApplicationController
|
102
|
-
|
103
|
-
before_action :require_user_logged_in, only: [:index, :show]
|
104
|
-
|
105
|
-
before_action :correct_user, only: [:edit]
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def index
|
110
|
-
|
111
|
-
@users = User.order(id: :desc).page(params[:page]).per(50)
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
def show
|
118
|
-
|
119
|
-
@user = User.find(params[:id])
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def new
|
126
|
-
|
127
|
-
@user = User.new
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
def create
|
134
|
-
|
135
|
-
@user = User.new(user_params)
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
if @user.save
|
140
|
-
|
141
|
-
flash[:success] = 'ユーザを登録しました。'
|
142
|
-
|
143
|
-
redirect_to @user
|
144
|
-
|
145
|
-
else
|
146
|
-
|
147
|
-
flash.now[:danger] = 'ユーザの登録に失敗しました。'
|
148
|
-
|
149
|
-
render :new
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
def edit
|
158
|
-
|
159
|
-
@user = User.find(params[:id])
|
160
|
-
|
161
|
-
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
def update
|
166
|
-
|
167
|
-
@user = User.find(params[:id])
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
if @user.update(user_params)
|
172
|
-
|
173
|
-
flash[:success] = 'プロフィールを変更しました。'
|
174
|
-
|
175
|
-
redirect_to @user
|
176
|
-
|
177
|
-
else
|
178
|
-
|
179
|
-
flash.now[:danger] = 'プロフィールが変更できませんでした。'
|
180
|
-
|
181
|
-
render :edit
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
private
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
def user_params
|
194
|
-
|
195
|
-
params.require(:user).permit(:name, :email, :password, :password_confirmation, :profession, :first_name, :last_name, :profile,)
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
def correct_user
|
202
|
-
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
```
|
208
|
-
|
209
|
-
```
|
210
|
-
|
211
|
-
users/show.html.erb
|
361
|
+
<div class="text-center">
|
362
|
+
|
363
|
+
<%= @skill.skill_description %>
|
364
|
+
|
365
|
+
</div>
|
366
|
+
|
367
|
+
</div>
|
368
|
+
|
369
|
+
</aside>
|
370
|
+
|
371
|
+
</div>
|
372
|
+
|
373
|
+
```
|
374
|
+
|
375
|
+
```
|
376
|
+
|
377
|
+
users/edit.html.erb
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
<div class="text-center">
|
382
|
+
|
383
|
+
<h1>プロフィール変更画面</h1>
|
384
|
+
|
385
|
+
</div>
|
212
386
|
|
213
387
|
|
214
388
|
|
215
389
|
<div class="row">
|
216
390
|
|
217
|
-
<
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
</d
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
<asi
|
230
|
-
|
231
|
-
<t
|
232
|
-
|
233
|
-
<
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
<
|
240
|
-
|
241
|
-
<tr>
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
<
|
248
|
-
|
249
|
-
<t
|
250
|
-
|
251
|
-
<t
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
<
|
258
|
-
|
259
|
-
<
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
<
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
<
|
276
|
-
|
277
|
-
<a
|
278
|
-
|
279
|
-
<di
|
280
|
-
|
281
|
-
<div
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
<
|
286
|
-
|
287
|
-
<
|
288
|
-
|
289
|
-
</
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
<
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
<di
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
</div>
|
312
|
-
|
313
|
-
</aside>
|
391
|
+
<div class="col-sm-6 offset-sm-3">
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
396
|
+
|
397
|
+
<%= render 'layouts/error_messages', model: f.object %>
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
<div class="form-group">
|
402
|
+
|
403
|
+
<%= f.label :profession, 'Profession' %>
|
404
|
+
|
405
|
+
<%= f.text_field :profession, class: 'form-control' %>
|
406
|
+
|
407
|
+
</div>
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
<div class="form-group">
|
412
|
+
|
413
|
+
<%= f.label :first_name, 'First Name' %>
|
414
|
+
|
415
|
+
<%= f.text_field :first_name, class: 'form-control' %>
|
416
|
+
|
417
|
+
</div>
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
<div class="form-group">
|
422
|
+
|
423
|
+
<%= f.label :last_name, 'Last Name' %>
|
424
|
+
|
425
|
+
<%= f.text_field :last_name, class: 'form-control' %>
|
426
|
+
|
427
|
+
</div>
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
<div class="form-group">
|
432
|
+
|
433
|
+
<%= f.label :profile, 'Profile' %>
|
434
|
+
|
435
|
+
<%= f.text_field :profile, class: 'form-control' %>
|
436
|
+
|
437
|
+
</div>
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
<div class="text-left">
|
442
|
+
|
443
|
+
<h3>Security</h3>
|
444
|
+
|
445
|
+
</div>
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
<div class="form-group">
|
450
|
+
|
451
|
+
<%= f.label :email, 'Email' %>
|
452
|
+
|
453
|
+
<%= f.email_field :email, class: 'form-control' %>
|
454
|
+
|
455
|
+
</div>
|
456
|
+
|
457
|
+
<div class="form-group">
|
458
|
+
|
459
|
+
<%= f.label :password, 'Password' %>
|
460
|
+
|
461
|
+
<%= f.password_field :password, class: 'form-control' %>
|
462
|
+
|
463
|
+
</div>
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
<div class="text-left">
|
472
|
+
|
473
|
+
<h3>SKILL</h3>
|
474
|
+
|
475
|
+
</div>
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
<%= render 'skills/edit', skills: @skills %>
|
480
|
+
|
481
|
+
<% end %>
|
482
|
+
|
483
|
+
</div>
|
314
484
|
|
315
485
|
</div>
|
316
486
|
|
@@ -318,150 +488,36 @@
|
|
318
488
|
|
319
489
|
```
|
320
490
|
|
321
|
-
|
491
|
+
skills/_edit.html.erb
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
492
|
+
|
326
|
-
|
327
|
-
|
493
|
+
|
328
|
-
|
329
|
-
|
494
|
+
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
<div class="row">
|
334
|
-
|
335
|
-
<div class="col-sm-6 offset-sm-3">
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
495
|
+
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
340
|
-
|
496
|
+
|
341
|
-
|
497
|
+
<%= render 'layouts/error_messages', model: f.object %>
|
342
|
-
|
343
|
-
|
344
|
-
|
498
|
+
|
499
|
+
|
500
|
+
|
345
|
-
|
501
|
+
<div class="form-group">
|
346
|
-
|
347
|
-
|
502
|
+
|
348
|
-
|
349
|
-
<%= f.text_field :profession, class: 'form-control' %>
|
350
|
-
|
351
|
-
</div>
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
<div class="form-group">
|
356
|
-
|
357
|
-
<%= f.label :first_name, 'First Name' %>
|
358
|
-
|
359
|
-
<%= f.text_field :first_name, class: 'form-control' %>
|
360
|
-
|
361
|
-
</div>
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
<div class="form-group">
|
366
|
-
|
367
|
-
<%= f.label :last_name, 'Last Name' %>
|
368
|
-
|
369
|
-
<%= f.text_field :last_name, class: 'form-control' %>
|
370
|
-
|
371
|
-
</div>
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
<div class="form-group">
|
376
|
-
|
377
|
-
|
503
|
+
<%= f.label :skill_title, 'Skill Title' %>
|
378
|
-
|
504
|
+
|
379
|
-
|
505
|
+
<%= f.text_field :skill_title, class: 'form-control' %>
|
380
|
-
|
381
|
-
</div>
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
<div class="text-left">
|
386
|
-
|
387
|
-
<h3>Security</h3>
|
388
506
|
|
389
507
|
</div>
|
390
508
|
|
391
|
-
|
392
|
-
|
509
|
+
|
510
|
+
|
393
|
-
|
511
|
+
<div class="form-group">
|
394
|
-
|
512
|
+
|
395
|
-
|
513
|
+
<%= f.label :skill_description, 'Skill Descriotion' %>
|
396
|
-
|
514
|
+
|
397
|
-
|
515
|
+
<%= f.text_field :skill_description, class: 'form-control' %>
|
398
|
-
|
399
|
-
</div>
|
400
|
-
|
401
|
-
<div class="form-group">
|
402
|
-
|
403
|
-
<%= f.label :password, 'Password' %>
|
404
|
-
|
405
|
-
<%= f.password_field :password, class: 'form-control' %>
|
406
|
-
|
407
|
-
</div>
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
<div class="text-left">
|
416
|
-
|
417
|
-
<h3>SKILL</h3>
|
418
516
|
|
419
517
|
</div>
|
420
518
|
|
421
519
|
|
422
520
|
|
423
|
-
<%= render 'skills/edit', skills: @skills %>
|
424
|
-
|
425
|
-
<% end %>
|
426
|
-
|
427
|
-
</div>
|
428
|
-
|
429
|
-
</div>
|
430
|
-
|
431
|
-
```
|
432
|
-
|
433
|
-
```
|
434
|
-
|
435
|
-
skills/_edit.html.erb
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
<%= form_with(model: @user, local: true, method: :put) do |f| %>
|
440
|
-
|
441
|
-
<%= render 'layouts/error_messages', model: f.object %>
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
<div class="form-group">
|
446
|
-
|
447
|
-
<%= f.label :skill_title, 'Skill Title' %>
|
448
|
-
|
449
|
-
<%= f.text_field :skill_title, class: 'form-control' %>
|
450
|
-
|
451
|
-
</div>
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
<div class="form-group">
|
456
|
-
|
457
|
-
<%= f.label :skill_description, 'Skill Descriotion' %>
|
458
|
-
|
459
|
-
<%= f.text_field :skill_description, class: 'form-control' %>
|
460
|
-
|
461
|
-
</div>
|
462
|
-
|
463
|
-
|
464
|
-
|
465
521
|
<%= f.submit '更新', class: 'btn btn-primary btn-block' %>
|
466
522
|
|
467
523
|
<% end %>
|