aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorNando Vieira <fnando.vieira@gmail.com>2010-09-18 20:36:44 -0300
committerJosé Valim <jose.valim@gmail.com>2010-09-24 12:49:27 +0200
commit7223fe7faf26f717aee056942aadecc62e8f5cd9 (patch)
treefd9388dd3235575bffae31851b46941c41c256a1 /actionpack/lib
parent275f922a23b780600a32f70de5b661371c8ffdf4 (diff)
downloadrails-7223fe7faf26f717aee056942aadecc62e8f5cd9.tar.gz
rails-7223fe7faf26f717aee056942aadecc62e8f5cd9.tar.bz2
rails-7223fe7faf26f717aee056942aadecc62e8f5cd9.zip
Make redirect_to accept blocks [#5643 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/redirecting.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb
index 10d7794b57..fb50fcae16 100644
--- a/actionpack/lib/action_controller/metal/redirecting.rb
+++ b/actionpack/lib/action_controller/metal/redirecting.rb
@@ -20,6 +20,7 @@ module ActionController
# * <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
# * <tt>String</tt> starting with <tt>protocol://</tt> (like <tt>http://</tt>) - Is passed straight through as the target for redirection.
# * <tt>String</tt> not containing a protocol - The current protocol and host is prepended to the string.
+ # * <tt>Proc</tt> - A block that will be executed in the controller's context. Should return any option accepted by +redirect_to+.
# * <tt>:back</tt> - Back to the page that issued the request. Useful for forms that are triggered from multiple places.
# Short-hand for <tt>redirect_to(request.env["HTTP_REFERER"])</tt>
#
@@ -30,6 +31,7 @@ module ActionController
# redirect_to "/images/screenshot.jpg"
# redirect_to articles_url
# redirect_to :back
+ # redirect_to proc { edit_post_url(@post) }
#
# The redirection happens as a "302 Moved" header unless otherwise specified.
#
@@ -38,7 +40,7 @@ module ActionController
# redirect_to :action=>'atom', :status => :moved_permanently
# redirect_to post_url(@post), :status => 301
# redirect_to :action=>'atom', :status => 302
- #
+ #
# The status code can either be a standard {HTTP Status code}[http://www.iana.org/assignments/http-status-codes] as an
# integer, or a symbol representing the downcased, underscored and symbolized description.
#
@@ -85,6 +87,8 @@ module ActionController
when :back
raise RedirectBackError unless refer = request.headers["Referer"]
refer
+ when Proc
+ _compute_redirect_to_location instance_eval(&options)
else
url_for(options)
end.gsub(/[\r\n]/, '')