Before saving an object record’s field value


Before saving a field value of the object record, the following options can be possible:

>>u=User.find_by_login("pradeep")
=> #(User id: 32, login: "pradeep", email: "p.pradeep@sedin.co.in", crypted_password: "f70c133388fc64d59c979efa00aff06d7f44ce20", salt: "059b6c5fcc86680ee5a453b33627075e553e0b0c", created_at: "2010-11-18 10:38:41", updated_at: "2010-11-20 12:50:55", remember_token: nil, remember_token_expires_at: nil, activation_code: nil, activated_at: "2010-11-18 11:17:28", state: "active", deleted_at: nil, admin: false, password_reset_code: nil, sent_activation: true)
>> u.admin
=> false
#initial value
>> u.admin=true
=> true
>> u.changed
=> ["admin"]
>> u.changed?
=> true
>> u.changes
=> {"admin"=>[false, true]}
>> u.admin_was
=> false
>> u.admin_change
=> [false, true]
>> u.admin_changed?
=> true
>> u.save
=> true

Leave a comment