質問編集履歴
2
登録されたメンバーのidを取得する方法がわかりません。
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,21 @@
|
|
123
123
|
end
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
追記2:
|
128
|
+
|
129
|
+
コンソールで試したところ
|
130
|
+
|
131
|
+
```ここに言語を入力
|
132
|
+
|
133
|
+
irb(main):002:0> StaffYear.create(staff_member_id: 5, year_check: 2018)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
で登録に成功しました。
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
staff_member_id :5で登録できましたが、5の部分を新規登録されたstaff_memberのidを
|
142
|
+
|
143
|
+
入れる方法を教えていただけないでしょうか?
|
1
エラー発生について記述しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -73,3 +73,53 @@
|
|
73
73
|
|
74
74
|
|
75
75
|
記述場所が悪いのか、コード自体が間違っているのかわからないのでどなたか教えていただけないでしょうか?宜しくお願いします。
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
追記
|
80
|
+
|
81
|
+
エラーが発生してしまいます。
|
82
|
+
|
83
|
+
```ここに言語を入力
|
84
|
+
|
85
|
+
StaffYear Load (0.8ms) SELECT `staff_years`.* FROM `staff_years` WHERE `staff_years`.`staff_member_id` = 5 LIMIT 1
|
86
|
+
|
87
|
+
(2.7ms) ROLLBACK
|
88
|
+
|
89
|
+
Completed 500 Internal Server Error in 256ms (ActiveRecord: 12.2ms)
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
NoMethodError (undefined method `create' for nil:NilClass):
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
app/models/staff_member.rb:35:in `save_staff_year'
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
```ここに言語を入力
|
108
|
+
|
109
|
+
実行したコード
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
after_create :create_staff_year
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def create_staff_year
|
120
|
+
|
121
|
+
self.staff_year.create(year_check: 2018)----ここでエラー発生。
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
```
|