LoginSignup
5
3

More than 5 years have passed since last update.

Railsのコールバック関数まとめ

Posted at

コールバック関数とは

コールバックとはデータベースへの保存の直前や、バリデーションの実行直後など特定のタイミングで処理を行うための機能です。
特定のタイミングで必ず実行されるコールバック関数を設定しておくことで、モデルの一貫性が保たれます。

コールバック関数の種類

  • after_find
  • after_initialize
  • before_validation
  • after_validation
  • before_save
  • before_create / before_update
  • after_create / after_update
  • after_save
  • after_commit
  • after_rollback
  • after_touch
  • before_destory
  • after_destory

参考:Railsのコールバックまとめ

5
3
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
5
3