Skip to content
This repository
Browse code

Better documentation for Calling multiple redirects or renders #1687

…[courtenay]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1795 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 14e7c7c21dcffd8f4388883eb241e0cc0ad23bbc 1 parent 383b6af
David Heinemeier Hansson authored July 10, 2005

Showing 1 changed file with 7 additions and 4 deletions. Show diff stats Hide diff stats

  1. 11  actionpack/lib/action_controller/base.rb
11  actionpack/lib/action_controller/base.rb
@@ -184,16 +184,19 @@ def initialize(message=nil)
184 184
   #
185 185
   # == Calling multiple redirects or renders
186 186
   #
187  
-  # The rule for handling calls of multiple redirects and renders is that the first call wins. So in the following example:
  187
+  # An action should conclude by a single render or redirect. Attempting to try to do either again will result in a DoubleRenderError:
188 188
   #
189 189
   #   def do_something
190 190
   #     redirect_to :action => "elsewhere"
191  
-  #     render :action => "overthere"
  191
+  #     render :action => "overthere" # raises DoubleRenderError
192 192
   #   end
193 193
   #
194  
-  # Only the redirect happens. The rendering call is simply ignored.
  194
+  # If you need to redirect on the condition of something, then be sure to add "and return" to halt execution.
195 195
   #
196  
-  # == Environments
  196
+  #   def do_something
  197
+  #     redirect_to(:action => "elsewhere") and return if monkeys.nil?
  198
+  #     render :action => "overthere" # won't be called unless monkeys is nil
  199
+  #   end  # == Environments
197 200
   #
198 201
   # Action Controller works out of the box with CGI, FastCGI, and mod_ruby. CGI and mod_ruby controllers are triggered just the same using:
199 202
   #

0 notes on commit 14e7c7c

Please sign in to comment.
Something went wrong with that request. Please try again.