LoginSignup
1
0

More than 1 year has passed since last update.

ActiveRecordのvalidationとbefore_saveの実行順序

Last updated at Posted at 2022-12-01

順番は以下。

validation1 -> validation2 -> before_save1 -> before_save2
  • validation1 でinstaneのerrosにエラーを追加しても、validation2は続いて呼ばれる。
  • validationが全て終わった時点で、そのinstanceのerrorsが空でない場合、before_saveは呼ばれない。
  • before_save1 で throw(:abort)した場合、before_save2は呼ばれない
  • before_save1 内で errosにエラーを追加することもできる。
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