質問編集履歴

3

applicatinコントローラーの追加

2018/07/10 06:51

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -477,3 +477,33 @@
477
477
  end
478
478
 
479
479
  ```
480
+
481
+ ```ruby
482
+
483
+ class ApplicationController < ActionController::Base
484
+
485
+ protect_from_forgery with: :exception
486
+
487
+ before_action :check_login
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+ private
496
+
497
+ def check_login
498
+
499
+ if session[:user_id]
500
+
501
+ @user = User.find_by(id: session[:user_id])
502
+
503
+ end
504
+
505
+ end
506
+
507
+ end
508
+
509
+ ```

2

誤字

2018/07/10 06:51

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- createアクションのsave前でbinding.pryで見てみると、以下のようにimageとuser_idが取得できません。controllerのactionの書き方が間違っているのでしょうか?
7
+ createアクションのsave前でbinding.pryを行うと、以下のようにimageとuser_idが取得できていません。controllerのactionの書き方が間違っているのでしょうか?
8
8
 
9
9
  ```
10
10
 

1

誤字

2018/07/10 05:27

投稿

Manamin
Manamin

スコア14

test CHANGED
File without changes
test CHANGED
@@ -2,13 +2,9 @@
2
2
 
3
3
 
4
4
 
5
- belongs_to :userにoptional: trueをつける前はUser not existとエラーが出ていました。
5
+
6
-
7
-
8
-
9
-
10
-
6
+
11
- しかし、createアクションのsave前でbinding.pryで見てみると、以下のようにimageとuser_idが取得できません。controllerのactionの書き方が間違っているのでしょうか?
7
+ createアクションのsave前でbinding.pryで見てみると、以下のようにimageとuser_idが取得できません。controllerのactionの書き方が間違っているのでしょうか?
12
8
 
13
9
  ```
14
10
 
@@ -20,6 +16,12 @@
20
16
 
21
17
 
22
18
 
19
+ なおbelongs_to :userにoptional: trueをつける前はUser not existとエラーが出ていました。
20
+
21
+
22
+
23
+
24
+
23
25
  主に使っているgemが以下です
24
26
 
25
27