Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created May 5, 2010 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tcocca/390769 to your computer and use it in GitHub Desktop.
Save tcocca/390769 to your computer and use it in GitHub Desktop.
class Recipe < ActiveRecord::Base
belongs_to :style, :counter_cache => true
attribute_method_suffix '_previous_change'
private
def attribute_previous_change(attr)
self.changes[attr]
end
end
######
@recipe = Recipe.find(1)
@recipe.style_id ## => 1
@recipe.style_id = 2
@recipe.save
@recipe.style_id_previous_change ## => [1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment