LoginSignup
6
7

More than 5 years have passed since last update.

フィールド更新時に更新前の値を使って処理する

Last updated at Posted at 2012-10-12

フィールドa_fieldの変更前の値はa_field_wasで取得できるので,例えば"値が変更されていたら実行する"という処理は,after_updateの中で以下のように書いてやればいい

my_model.rb
class MyModel < ActiveRecord::Base
  after_update do 
    do_something if a_field != a_field_was
  end
end
6
7
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
6
7