@@ -298,6 +298,19 class ApplicationController < ActionController::Base | |||
|
298 | 298 | false |
|
299 | 299 | end |
|
300 | 300 | |
|
301 | # Redirects to the request referer if present, redirects to args or call block otherwise. | |
|
302 | def redirect_to_referer_or(*args, &block) | |
|
303 | redirect_to :back | |
|
304 | rescue ::ActionController::RedirectBackError | |
|
305 | if args.any? | |
|
306 | redirect_to *args | |
|
307 | elsif block_given? | |
|
308 | block.call | |
|
309 | else | |
|
310 | raise "#redirect_to_referer_or takes arguments or a block" | |
|
311 | end | |
|
312 | end | |
|
313 | ||
|
301 | 314 | def render_403(options={}) |
|
302 | 315 | @project = nil |
|
303 | 316 | render_error({:message => :notice_not_authorized, :status => 403}.merge(options)) |
@@ -88,9 +88,7 class AttachmentsController < ApplicationController | |||
|
88 | 88 | end |
|
89 | 89 | # Make sure association callbacks are called |
|
90 | 90 | @attachment.container.attachments.delete(@attachment) |
|
91 | redirect_to :back | |
|
92 | rescue ::ActionController::RedirectBackError | |
|
93 | redirect_to :controller => 'projects', :action => 'show', :id => @project | |
|
91 | redirect_back_or_default project_path(@project) | |
|
94 | 92 | end |
|
95 | 93 | |
|
96 | 94 | private |
@@ -154,7 +154,7 class UsersController < ApplicationController | |||
|
154 | 154 | respond_to do |format| |
|
155 | 155 | format.html { |
|
156 | 156 | flash[:notice] = l(:notice_successful_update) |
|
157 | redirect_to :back | |
|
157 | redirect_to_referer_or edit_user_path(@user) | |
|
158 | 158 | } |
|
159 | 159 | format.api { head :ok } |
|
160 | 160 | end |
@@ -169,8 +169,6 class UsersController < ApplicationController | |||
|
169 | 169 | format.api { render_validation_errors(@user) } |
|
170 | 170 | end |
|
171 | 171 | end |
|
172 | rescue ::ActionController::RedirectBackError | |
|
173 | redirect_to :controller => 'users', :action => 'edit', :id => @user | |
|
174 | 172 | end |
|
175 | 173 | |
|
176 | 174 | def destroy |
@@ -52,7 +52,7 class WatchersController < ApplicationController | |||
|
52 | 52 | end |
|
53 | 53 | end |
|
54 | 54 | respond_to do |format| |
|
55 | format.html { redirect_to :back } | |
|
55 | format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} | |
|
56 | 56 | format.js do |
|
57 | 57 | render :update do |page| |
|
58 | 58 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
@@ -60,8 +60,6 class WatchersController < ApplicationController | |||
|
60 | 60 | end |
|
61 | 61 | end |
|
62 | 62 | end |
|
63 | rescue ::ActionController::RedirectBackError | |
|
64 | render :text => 'Watcher added.', :layout => true | |
|
65 | 63 | end |
|
66 | 64 | |
|
67 | 65 | def append |
@@ -120,7 +118,7 private | |||
|
120 | 118 | def set_watcher(user, watching) |
|
121 | 119 | @watched.set_watcher(user, watching) |
|
122 | 120 | respond_to do |format| |
|
123 | format.html { redirect_to :back } | |
|
121 | format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} | |
|
124 | 122 | format.js do |
|
125 | 123 | render(:update) do |page| |
|
126 | 124 | c = watcher_css(@watched) |
@@ -130,7 +128,5 private | |||
|
130 | 128 | end |
|
131 | 129 | end |
|
132 | 130 | end |
|
133 | rescue ::ActionController::RedirectBackError | |
|
134 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true | |
|
135 | 131 | end |
|
136 | 132 | end |
General Comments 0
You need to be logged in to leave comments.
Login now