Avoiding after_save callback that relies on activerecord.changed?

I’m trying to avoid to using an after_save active record callback that relies on the attributes being changed.

Basically, I want to create a class that takes a active record object that executes some code if certain attributes have changed on last save.

The problem is that all active record change tracking is removed after call .save on the object. Any suggestions for how to accomplish this without using an after save callback?

@Nicolo can you provide more concrete examples of what the attributes are, what they are changing to, and why it needs to be triggered off the attribute changing?

Yes I import stats for players and save them to my database. I want to update the player’s statistics on the client via Pusher. I only want to send a request to pusher if the stats are actually changed for that player.

@Nicolo I think ActiveModel::Dirty#previous_changes might be what you’re looking for. It returns a Hash of attributes that were changed before the model was saved.

@calleerlandsson I think that will do it. Thanks for finding that. I can’t believe I missed that.

No problem @Nicolo.