Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

multisite: Fix broken article versions

[This is an edited version of the author's blog post at
http://inormalized.com/2009/2/19/how-to-fix-broken-article-versions-in-emk-mephisto-edge-post-0-8-1. -Eric]

Currently in mephisto edge, article versions are broken. More precisely,
the bug comes up ONLY when the installation operates in multisite mode
(or even more precisely, when there are at least two articles belonging
to two different sites).

The problem is how acts_as_versioned is being used. An acts_as_versioned
record has among others an “id” column (the default id that ActiveRecord
requires) and a “version” column.

Currently Mephisto falsely does the following inside
\app\controllers\admin\articles_controller.rb on line 38 (edit
action)...

  @version = params[:version] ? @article.versions.find(params[:version]) : @article or raise(ActiveRecord::RecordNotFound)

the whole problem is the find(params[:version]) . What happens here is,
that we lookup an article’s version by searching for its id instead of
for its version column (even though we do use the correct :version
parameter.)

So this has to change to find_by_version(params[:version]) and thus
become..

  @version = params[:version] ? @article.versions.find_by_version(params[:version]) : @article or raise(ActiveRecord::RecordNotFound)

Notice though that this doesn’t break in a single-site installation,
because in this case id and version bot get the same (concurrent)
increment. That is because all articles belong the same one and only
Site instance.
  • Loading branch information...
commit 0535b5ff99d45c94e6cb5d54d8ddaf24081840bd 1 parent c05e9ee
Spyridon Vasileiadis authored emk committed
Showing with 1 addition and 1 deletion.
  1. +1 −1  app/controllers/admin/articles_controller.rb
View
2  app/controllers/admin/articles_controller.rb
@@ -38,7 +38,7 @@ def new
end
def edit
- @version = params[:version] ? @article.versions.find(params[:version]) : @article or raise(ActiveRecord::RecordNotFound)
+ @version = params[:version] ? @article.versions.find_by_version(params[:version]) : @article or raise(ActiveRecord::RecordNotFound)
@published = @version.published?
@version.published_at = utc_to_local(@version.published_at || Time.now.utc)
end
Please sign in to comment.
Something went wrong with that request. Please try again.