diff options
| author | hukl <contact@smyck.org> | 2009-09-03 20:40:15 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-09-03 20:40:15 +0200 |
| commit | 50a03a184ca867ce0962b3a5980261b1912c8c26 (patch) | |
| tree | 1c5ba475e73dd88ee7a94d0428523ae4a909b9cd | |
| parent | d749383308a19b7c284ef199f715a2713bd5b7ca (diff) | |
more graceful handling of locked pages exceptions.
| -rw-r--r-- | app/controllers/nodes_controller.rb | 7 | ||||
| -rw-r--r-- | app/models/node.rb | 4 |
2 files changed, 9 insertions, 2 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 09d0c52..07bbbac 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -43,7 +43,12 @@ class NodesController < ApplicationController | |||
| 43 | end | 43 | end |
| 44 | 44 | ||
| 45 | def edit | 45 | def edit |
| 46 | @draft = @node.find_or_create_draft( current_user ) | 46 | begin |
| 47 | @draft = @node.find_or_create_draft( current_user ) | ||
| 48 | rescue LockedByAnotherUser | ||
| 49 | flash[:error] = "Page is locked by another user who is working on it!" | ||
| 50 | redirect_to :back | ||
| 51 | end | ||
| 47 | end | 52 | end |
| 48 | 53 | ||
| 49 | def update | 54 | def update |
diff --git a/app/models/node.rb b/app/models/node.rb index b45ba80..318c203 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -61,7 +61,7 @@ class Node < ActiveRecord::Base | |||
| 61 | draft.save | 61 | draft.save |
| 62 | draft | 62 | draft |
| 63 | elsif draft && self.lock_owner != current_user | 63 | elsif draft && self.lock_owner != current_user |
| 64 | raise "Page is locked" | 64 | raise LockedByAnotherUser |
| 65 | else | 65 | else |
| 66 | lock_for! current_user | 66 | lock_for! current_user |
| 67 | create_new_draft current_user | 67 | create_new_draft current_user |
| @@ -154,4 +154,6 @@ class Node < ActiveRecord::Base | |||
| 154 | end | 154 | end |
| 155 | end | 155 | end |
| 156 | 156 | ||
| 157 | class LockedByAnotherUser < StandardError; end | ||
| 158 | |||
| 157 | 159 | ||
