fix for post archive presenter

This commit is contained in:
r888888888
2017-05-02 15:50:58 -07:00
parent 25b2f73546
commit e96e9c0105

View File

@@ -98,7 +98,7 @@ class PostArchive < ActiveRecord::Base
def previous
# HACK: if all the post versions for this post have already been preloaded,
# we can use that to avoid a SQL query.
if association(:post).loaded? && post.association(:versions).loaded?
if association(:post).loaded? && post && post.association(:versions).loaded?
post.versions.sort_by(&:version).reverse.find { |v| v.version < version }
else
PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").first