fixes #357
This commit is contained in:
@@ -105,6 +105,30 @@ class PostVersion < ActiveRecord::Base
|
|||||||
}
|
}
|
||||||
end
|
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
|
def previous
|
||||||
PostVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).order("updated_at desc").first
|
PostVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).order("updated_at desc").first
|
||||||
end
|
end
|
||||||
@@ -141,4 +165,23 @@ class PostVersion < ActiveRecord::Base
|
|||||||
undo
|
undo
|
||||||
post.save!
|
post.save!
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user