Rails detect changes in database fields

You can check if any field of any record is changed or not. It basically compares the new value you assign and the original value in the local cache (or in the database)

[1] > self.changed?
 => true
 [2] > self.changed
 => ["shipped_at"]
 [3] > self.changes
 => {"shipped_at"=>[Sat, 02 Jan 2016 00:00:00 UTC +00:00, Mon, 11 Jan 2016 00:00:00 UTC +00:00]}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s