This commit is contained in:
Toks
2013-08-13 13:15:07 -04:00
parent d4060a647d
commit 2c80f9bcc4

View File

@@ -105,6 +105,30 @@ class PostVersion < ActiveRecord::Base
}
end
def changes
@changes ||= diff(previous)
end
def added_tags
changes[:added_tags].join(" ")
end
def removed_tags
changes[:removed_tags].join(" ")
end
def obsolete_added_tags
changes[:obsolete_added_tags].join(" ")
end
def obsolete_removed_tags
changes[:obsolete_removed_tags].join(" ")
end
def unchanged_tags
changes[:unchanged_tags].join(" ")
end
def previous
PostVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).order("updated_at desc").first
end
@@ -141,4 +165,23 @@ class PostVersion < ActiveRecord::Base
undo
post.save!
end
def serializable_hash(options = {})
options ||= {}
options[:except] ||= []
options[:except] += hidden_attributes
unless options[:builder]
options[:methods] ||= []
options[:methods] += [:added_tags, :removed_tags, :obsolete_added_tags, :obsolete_removed_tags, :unchanged_tags]
end
hash = super(options)
hash
end
def to_xml(options = {}, &block)
options ||= {}
options[:methods] ||= []
options[:methods] += [:added_tags, :removed_tags, :obsolete_added_tags, :obsolete_removed_tags, :unchanged_tags]
super(options, &block)
end
end