LoginSignup
1
0

More than 3 years have passed since last update.

validationを設定していないのにエラーが出るとき

Posted at

なぜだ

ActiveRecord::RecordInvalid: バリデーションに失敗しました

modelを確認してもマイグレーションファイルを確認してもどこにも
validationの設定はない。

それなのに出続けるエラー。

原因

Rails5からの変更でbelongs_toに存在性のvalidationが設定されたようです。

なので以下のように変更

belongs_to :post_id, optional: true

参考

https://railsguides.jp/association_basics.html

https://teratail.com/questions/65278

1
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
1
0