質問編集履歴

2

フォームオブジェクトへゲッターの追加

2020/09/24 09:34

投稿

bata1016
bata1016

スコア2

test CHANGED
File without changes
test CHANGED
@@ -30,11 +30,11 @@
30
30
 
31
31
  @document = DocumentFolder.new(document_params)
32
32
 
33
+ @user_id = DocumentFolder.get_user_id(current_user.id)
34
+
33
35
 
34
36
 
35
37
  if @document.valid?
36
-
37
- @user_id = current_user.id
38
38
 
39
39
  @document.save
40
40
 
@@ -47,22 +47,6 @@
47
47
 
48
48
 
49
49
  end
50
-
51
-
52
-
53
-
54
-
55
- private
56
-
57
- def document_params
58
-
59
- params.require(:document_folder).permit(:document_name, :folder_name, :image)
60
-
61
- end
62
-
63
-
64
-
65
- end
66
50
 
67
51
  ```
68
52
 
@@ -96,6 +80,18 @@
96
80
 
97
81
 
98
82
 
83
+ private
84
+
85
+ def self.get_user_id(user_id)
86
+
87
+ user_id
88
+
89
+ end
90
+
91
+
92
+
93
+
94
+
99
95
  def save
100
96
 
101
97
  folder = Folder.create(folder_name: folder_name, user_id: @user_id)

1

フォームオブジェクト内の@userの訂正

2020/09/24 09:34

投稿

bata1016
bata1016

スコア2

test CHANGED
File without changes
test CHANGED
@@ -98,11 +98,11 @@
98
98
 
99
99
  def save
100
100
 
101
- folder = Folder.create(folder_name: folder_name, user_id: @user)
101
+ folder = Folder.create(folder_name: folder_name, user_id: @user_id)
102
102
 
103
103
  binding.pry
104
104
 
105
- Document.create!(document_name: document_name, image: image, user_id: @user, folder_id: folder.id)
105
+ Document.create!(document_name: document_name, image: image, user_id: @user_id, folder_id: folder.id)
106
106
 
107
107
  end
108
108