Fixed problems in interacting of acts_as_versioned and optimistic locking.
This commit is contained in:
parent
2660d86b89
commit
255a4cd6c7
5 changed files with 9 additions and 10 deletions
|
@ -19,7 +19,8 @@ class PagesController < ApplicationController
|
|||
end
|
||||
|
||||
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|
|
||||
format.html # new.html.erb
|
||||
|
@ -83,13 +84,13 @@ class PagesController < ApplicationController
|
|||
|
||||
def version
|
||||
@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
|
||||
|
||||
def revert
|
||||
@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
|
||||
|
|
|
@ -2,7 +2,7 @@ class Page < ActiveRecord::Base
|
|||
|
||||
belongs_to :user, :foreign_key => 'updated_by'
|
||||
|
||||
acts_as_versioned
|
||||
acts_as_versioned :version_column => :lock_version
|
||||
self.non_versioned_columns += ['permalink', 'created_at']
|
||||
|
||||
validates_presence_of :title, :body
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
%ul
|
||||
- for version in @page.versions.reverse
|
||||
%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})"
|
||||
|
||||
|
||||
= render :partial => 'body'
|
||||
|
||||
%hr.clear/
|
||||
|
@ -19,4 +18,4 @@
|
|||
|
|
||||
= 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})"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
%ul
|
||||
%li= "Autor: #{User.find(@version.updated_by).nick}"
|
||||
%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
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ class CreatePages < ActiveRecord::Migration
|
|||
t.string :permalink
|
||||
t.integer :lock_version, :default => 0
|
||||
t.integer :updated_by
|
||||
t.integer :version
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue