<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -38,7 +38,7 @@ class Admin::ArticlesController &lt; Admin::BaseController
   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</diff>
      <filename>app/controllers/admin/articles_controller.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c05e9ee1c3e6580b0bff72051c294cc955581001</id>
    </parent>
  </parents>
  <author>
    <name>Spyridon Vasileiadis</name>
    <email>spyridon.vasileiadis@googlemail.com</email>
  </author>
  <url>http://github.com/emk/mephisto/commit/0535b5ff99d45c94e6cb5d54d8ddaf24081840bd</url>
  <id>0535b5ff99d45c94e6cb5d54d8ddaf24081840bd</id>
  <committed-date>2009-03-15T06:56:38-07:00</committed-date>
  <authored-date>2009-03-15T06:53:26-07:00</authored-date>
  <message>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 &#8220;id&#8221; column (the default id that ActiveRecord
requires) and a &#8220;version&#8221; 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&#8217;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&#8217;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.</message>
  <tree>a89976f39245db9125dfb1dc3f21c0430d87953a</tree>
  <committer>
    <name>Eric Kidd</name>
    <email>git@randomhacks.net</email>
  </committer>
</commit>
