diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 4dbe5807..35caf0b3 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -56,16 +56,16 @@ class PagesController < ApplicationController def update @page = Page.find(params[:id]) - respond_to do |format| - if @page.update_attributes(params[:page]) - flash[:notice] = 'Seite wurde aktualisiert.' - format.html { redirect_to(wiki_page_path(@page.permalink)) } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @page.errors, :status => :unprocessable_entity } - end + if @page.update_attributes(params[:page]) + flash[:notice] = 'Seite wurde aktualisiert.' + redirect_to wiki_page_path(@page.permalink) + else + render :action => "edit" 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 # DELETE /pages/1 diff --git a/app/views/pages/_form.html.haml b/app/views/pages/_form.html.haml index 0c3645f7..b85bdebb 100644 --- a/app/views/pages/_form.html.haml +++ b/app/views/pages/_form.html.haml @@ -15,7 +15,7 @@ - form_for @page do |f| = f.error_messages - + = f.hidden_field :lock_version %p %b Title %br/ diff --git a/db/migrate/20090325175756_create_pages.rb b/db/migrate/20090325175756_create_pages.rb index cca1e419..8338afac 100644 --- a/db/migrate/20090325175756_create_pages.rb +++ b/db/migrate/20090325175756_create_pages.rb @@ -4,6 +4,7 @@ class CreatePages < ActiveRecord::Migration t.string :title t.text :body t.string :permalink + t.integer :lock_version, :default => 0 t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 92c4a70d..3307abc3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -215,6 +215,7 @@ ActiveRecord::Schema.define(:version => 20090325175756) do t.string "title" t.text "body" t.string "permalink" + t.integer "lock_version", :default => 0 t.datetime "created_at" t.datetime "updated_at" end