The strong parameter is true, but for some reason it cannot be saved in the table.

What didn't work

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

Conclusion

I didn't put it in the migration file even though I had an association and the foreign key should exist.

Verification method (save! Method)

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

The strong parameter is true, but for some reason it cannot be saved in the table.
In DynamoDB Enhanced Client, I access the index table for some reason
I specified the version and rails new, but for some reason the latest version is included ~
[For beginners] Ruby is said to be ruby, but what about it?
Build error for The file ca n’t be saved in Xcode
If you get the error The data ca n’t be read because it is missing in docker for mac
How to translate the error message into Japanese (What to do if you cannot log in for some reason)
If the parameter is an array, how to include it in Stopara's params.permit
In case of exception, waiting for debugger is redisplayed and Logcat exception cannot be seen.
Asynchronous processing executed in Future in Swift Combine is sinking, but it is canceled in the middle