public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
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
dhh (author)
Sat Jul 09 22:26:55 -0700 2005
commit  14e7c7c21dcffd8f4388883eb241e0cc0ad23bbc
tree    f80064d5883fff3be1461b2ce9a568e2d48807d2
parent  383b6afd1c943096951ea845b3fc726f4d2193a6
...
184
185
186
187
 
188
189
190
191
 
192
193
194
 
195
196
 
 
 
 
197
198
199
...
184
185
186
 
187
188
189
190
 
191
192
193
 
194
195
 
196
197
198
199
200
201
202
0
@@ -184,16 +184,19 @@
0
   #
0
   # == Calling multiple redirects or renders
0
   #
0
- # The rule for handling calls of multiple redirects and renders is that the first call wins. So in the following example:
0
+ # An action should conclude by a single render or redirect. Attempting to try to do either again will result in a DoubleRenderError:
0
   #
0
   # def do_something
0
   # redirect_to :action => "elsewhere"
0
- # render :action => "overthere"
0
+ # render :action => "overthere" # raises DoubleRenderError
0
   # end
0
   #
0
- # Only the redirect happens. The rendering call is simply ignored.
0
+ # If you need to redirect on the condition of something, then be sure to add "and return" to halt execution.
0
   #
0
- # == Environments
0
+ # def do_something
0
+ # redirect_to(:action => "elsewhere") and return if monkeys.nil?
0
+ # render :action => "overthere" # won't be called unless monkeys is nil
0
+ # end # == Environments
0
   #
0
   # Action Controller works out of the box with CGI, FastCGI, and mod_ruby. CGI and mod_ruby controllers are triggered just the same using:
0
   #

Comments

    No one has commented yet.