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