Skip to content

Instantly share code, notes, and snippets.

@hayesr
Forked from beanieboi/mongoid version diff
Created June 23, 2012 18:21
Show Gist options
  • Save hayesr/2979294 to your computer and use it in GitHub Desktop.
Save hayesr/2979294 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