Skip to content

Instantly share code, notes, and snippets.

@beanieboi
Created January 26, 2011 13:13
Show Gist options
  • Save beanieboi/796664 to your computer and use it in GitHub Desktop.
Save beanieboi/796664 to your computer and use it in GitHub Desktop.
shows the diff between two versions when you use Mongoid::Versioning
def compare_to(version)
reject_fields = ["_id", "updated_at", "version"]
diff_array = self.versions[version-1].attributes.to_hash.to_a - self.attributes.to_hash.to_a
diff_array.delete_if {|f| reject_fields.include?(f.first) }
Hash[diff_array]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment