]> source.dussan.org Git - redmine.git/commitdiff
Code cleanup.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 6 Apr 2012 16:51:10 +0000 (16:51 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 6 Apr 2012 16:51:10 +0000 (16:51 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9363 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application_controller.rb
app/controllers/attachments_controller.rb
app/controllers/users_controller.rb
app/controllers/watchers_controller.rb

index bf62d7ff27db750f6344b800eab33210fa7cb520..bdd3e6a9f3ee551b711e7bc7427408e543d2cd36 100644 (file)
@@ -298,6 +298,19 @@ class ApplicationController < ActionController::Base
     false
   end
 
+  # Redirects to the request referer if present, redirects to args or call block otherwise.
+  def redirect_to_referer_or(*args, &block)
+    redirect_to :back
+  rescue ::ActionController::RedirectBackError
+    if args.any?
+      redirect_to *args
+    elsif block_given?
+      block.call
+    else
+      raise "#redirect_to_referer_or takes arguments or a block"
+    end
+  end
+
   def render_403(options={})
     @project = nil
     render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
index 967032d92b86214640d8ef4a82b4eab5d786e1dc..425bfab941fad9615536dfa92848b7a2bd6b4169 100644 (file)
@@ -88,9 +88,7 @@ class AttachmentsController < ApplicationController
     end
     # Make sure association callbacks are called
     @attachment.container.attachments.delete(@attachment)
-    redirect_to :back
-  rescue ::ActionController::RedirectBackError
-    redirect_to :controller => 'projects', :action => 'show', :id => @project
+    redirect_back_or_default project_path(@project)
   end
 
 private
index d22dd33cd7a29c4b1c1764476929c43dde1e5922..3bae5c05778ac59691568f7b3fb1217ec6a21d9f 100644 (file)
@@ -154,7 +154,7 @@ class UsersController < ApplicationController
       respond_to do |format|
         format.html {
           flash[:notice] = l(:notice_successful_update)
-          redirect_to :back
+          redirect_to_referer_or edit_user_path(@user)
         }
         format.api  { head :ok }
       end
@@ -169,8 +169,6 @@ class UsersController < ApplicationController
         format.api  { render_validation_errors(@user) }
       end
     end
-  rescue ::ActionController::RedirectBackError
-    redirect_to :controller => 'users', :action => 'edit', :id => @user
   end
 
   def destroy
index 19af1e672e5ab6b4193ba5b690b85436f37851d5..00f64702371d3075ec8046cb201cca9247e2d9f7 100644 (file)
@@ -52,7 +52,7 @@ class WatchersController < ApplicationController
       end
     end
     respond_to do |format|
-      format.html { redirect_to :back }
+      format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
       format.js do
         render :update do |page|
           page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
@@ -60,8 +60,6 @@ class WatchersController < ApplicationController
         end
       end
     end
-  rescue ::ActionController::RedirectBackError
-    render :text => 'Watcher added.', :layout => true
   end
 
   def append
@@ -120,7 +118,7 @@ private
   def set_watcher(user, watching)
     @watched.set_watcher(user, watching)
     respond_to do |format|
-      format.html { redirect_to :back }
+      format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
       format.js do
         render(:update) do |page|
           c = watcher_css(@watched)
@@ -130,7 +128,5 @@ private
         end
       end
     end
-  rescue ::ActionController::RedirectBackError
-    render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true
   end
 end