Fixed problems in interacting of acts_as_versioned and optimistic locking.

This commit is contained in:
Benjamin Meichsner 2009-05-20 15:26:53 +02:00
parent 2660d86b89
commit 255a4cd6c7
5 changed files with 9 additions and 10 deletions

View file

@ -19,7 +19,8 @@ class PagesController < ApplicationController
end end
def new def new
@page = Page.new(:title => params[:title].capitalize.gsub("-", " ")) @page = Page.new
@page.title = params[:title].capitalize.gsub("-", " ") if params[:title]
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
@ -83,13 +84,13 @@ class PagesController < ApplicationController
def version def version
@page = Page.find(params[:id]) @page = Page.find(params[:id])
@version = @page.versions[params[:version].to_i - 1] @version = Page::Version.find_by_page_id_and_lock_version params[:id], params[:version]
end end
def revert def revert
@page = Page.find(params[:id]) @page = Page.find(params[:id])
@page.revert_to(params[:version].to_i) @page.revert_to!(params[:version].to_i)
render :action => 'edit' redirect_to wiki_page_path(@page.permalink)
end end
end end

View file

@ -2,7 +2,7 @@ class Page < ActiveRecord::Base
belongs_to :user, :foreign_key => 'updated_by' belongs_to :user, :foreign_key => 'updated_by'
acts_as_versioned acts_as_versioned :version_column => :lock_version
self.non_versioned_columns += ['permalink', 'created_at'] self.non_versioned_columns += ['permalink', 'created_at']
validates_presence_of :title, :body validates_presence_of :title, :body

View file

@ -7,10 +7,9 @@
%ul %ul
- for version in @page.versions.reverse - for version in @page.versions.reverse
%li %li
= link_to format_time(version.updated_at), version_page_path(@page, :version => version.version) = link_to format_datetime(version.updated_at), version_page_path(@page, :version => version.lock_version)
= "(#{User.find(version.updated_by).nick})" = "(#{User.find(version.updated_by).nick})"
= render :partial => 'body' = render :partial => 'body'
%hr.clear/ %hr.clear/
@ -19,4 +18,4 @@
| |
= link_to "Seite löschen", @page, :method => :delete, :confirm => "Achtung, möchtest Du wirklich die Wikiseite löschen?" = link_to "Seite löschen", @page, :method => :delete, :confirm => "Achtung, möchtest Du wirklich die Wikiseite löschen?"
| |
= "Zuletzt bearbeitet: #{format_datetime @page.updated_at} (#{@page.user.nick})" = "Zuletzt bearbeitet am #{format_datetime @page.updated_at} (#{@page.user.nick})"

View file

@ -5,7 +5,7 @@
%ul %ul
%li= "Autor: #{User.find(@version.updated_by).nick}" %li= "Autor: #{User.find(@version.updated_by).nick}"
%li= link_to "Aktuelle Version sehen", wiki_page_path(:permalink => @page.permalink) %li= link_to "Aktuelle Version sehen", wiki_page_path(:permalink => @page.permalink)
%li= link_to "Auf diese Version zurücksetzen", revert_page_path(@page, :version => @version.version) %li= link_to "Auf diese Version zurücksetzen", revert_page_path(@page, :version => @version.lock_version)
= wikified_body @version.body = wikified_body @version.body

View file

@ -6,7 +6,6 @@ class CreatePages < ActiveRecord::Migration
t.string :permalink t.string :permalink
t.integer :lock_version, :default => 0 t.integer :lock_version, :default => 0
t.integer :updated_by t.integer :updated_by
t.integer :version
t.timestamps t.timestamps
end end