LoginSignup
0
0

More than 3 years have passed since last update.

Rails must be exist系のエラー(@saveが実行されない)

Posted at

結論

belongs_toにoptional: trueを追加。

belongs_to :post, optional: true

なぜか?

Rails5から、デフォルトで紐づけているテーブル同士の、どちらかにデータが無いままDBに格納しようとすると、エラーになる。だから、どちらにデータがない状態のままでもokに」するために'optional: true'を書く必要がある。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0