Added optimistic locking to wiki pages.
This commit is contained in:
parent
f83d2659de
commit
7ba6bc3680
4 changed files with 12 additions and 10 deletions
|
@ -56,16 +56,16 @@ class PagesController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
if @page.update_attributes(params[:page])
|
||||||
if @page.update_attributes(params[:page])
|
flash[:notice] = 'Seite wurde aktualisiert.'
|
||||||
flash[:notice] = 'Seite wurde aktualisiert.'
|
redirect_to wiki_page_path(@page.permalink)
|
||||||
format.html { redirect_to(wiki_page_path(@page.permalink)) }
|
else
|
||||||
format.xml { head :ok }
|
render :action => "edit"
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue ActiveRecord::StaleObjectError
|
||||||
|
flash[:error] = "Achtung, die Seite wurde gerade von jemand anderes bearbeitet. Bitte versuche es erneut."
|
||||||
|
redirect_to wiki_page_path(@page.permalink)
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /pages/1
|
# DELETE /pages/1
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
- form_for @page do |f|
|
- form_for @page do |f|
|
||||||
= f.error_messages
|
= f.error_messages
|
||||||
|
= f.hidden_field :lock_version
|
||||||
%p
|
%p
|
||||||
%b Title
|
%b Title
|
||||||
%br/
|
%br/
|
||||||
|
|
|
@ -4,6 +4,7 @@ class CreatePages < ActiveRecord::Migration
|
||||||
t.string :title
|
t.string :title
|
||||||
t.text :body
|
t.text :body
|
||||||
t.string :permalink
|
t.string :permalink
|
||||||
|
t.integer :lock_version, :default => 0
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
|
@ -215,6 +215,7 @@ ActiveRecord::Schema.define(:version => 20090325175756) do
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "body"
|
t.text "body"
|
||||||
t.string "permalink"
|
t.string "permalink"
|
||||||
|
t.integer "lock_version", :default => 0
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue