質問編集履歴
1
参考にしているサイトを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -547,3 +547,35 @@
|
|
547
547
|
end
|
548
548
|
|
549
549
|
```
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
ちなみに参考にしているサイトは[railsでユーザーと投稿を紐付ける](https://qiita.com/you8/items/63ad0b9c07da4323fe26)です。
|
554
|
+
|
555
|
+
これをもとに、application_controller_rbはこのようになっています。
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
```
|
560
|
+
|
561
|
+
class ApplicationController < ActionController::Base
|
562
|
+
|
563
|
+
protect_from_forgery with: :exception
|
564
|
+
|
565
|
+
include SessionsHelper
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
before_action :set_current_user
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
def set_current_user
|
574
|
+
|
575
|
+
@current_user = User.find_by(id: session[:user_id])
|
576
|
+
|
577
|
+
end
|
578
|
+
|
579
|
+
end
|
580
|
+
|
581
|
+
```
|