infoMore 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にエラーを追加することもできる。
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
What you can do with signing up