I can't save to the table even though params contains values. There is no error.
Terminal
6: def create
7: judge = Judge.new(judge_params)
8: judge.save
=> 9: binding.pry
10:
11: redirect_to root_path
12: end
[1] pry(#<JudgesController>)> judge
=> #<Judge:0x00007fd58efb37c0
id: nil,
judge_correct_id: 2,
comment: "Meo",
created_at: nil,
updated_at: nil>
[2] pry(#<JudgesController>)> judge.save
=> false
I didn't put it in the migration file even though I had an association and the foreign key should exist.
The save method only returns true or false, but if the save! method is false, it seems to raise an exception, so the terminal shows that it is causing the error. When false is returned as an instance variable .save on the terminal, it is changed to an instance variable .save!
Validation failed: User must exist,Post must exist ・ ・ ・ hogehoge
There was a description. I thought that I did not create the id related to User and Post even though I was forming an association, so I added it and it worked.
that's all
Recommended Posts