Skip to content

Instantly share code, notes, and snippets.

@erez-rabih
Created July 21, 2012 10:57
Show Gist options
  • Save erez-rabih/3155431 to your computer and use it in GitHub Desktop.
Save erez-rabih/3155431 to your computer and use it in GitHub Desktop.
u = User.create!(:name => "user1", :adderss => "address1", :current_job => "job1")
u.address = "address2"
u.current_job = "job2"
u.current_job_changed? # => true
u.address_changed? # => true
u.changed? # => true
u.changed # => ['address', 'current_job']
u.tracked.current_job_changed? # => false
u.tracked.address_changed? # => false
u.tracked.changed? # => false
u.tracked.changed # => []
u.save!
u.current_job_changed? # => false
u.address_changed? # => false
u.changed? # => false
u.changed # => []
u.tracked.current_job_changed? # => true
u.tracked.address_changed? # => true
u.tracked.changed? # => true
u.tracked.changed # => ['address', 'current_job']
u.tracked.set_unchanged(:current_job)
u.tracked.current_job_changed? # => false
u.tracked.set_changed(:current_job)
u.tracked.current_job_changed? # => true
u.tracked.set_all_unchanged
u.tracked.changed? # => false
u.tracked.changed # => []
u.tracked.set_all_changed
u.tracked.changed? # => true
u.tracked.changed # => ['address', 'current_job'] # note name is not changed - only tracked attributes are marked as changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment