From 02ce569e740a83d0737fca7de461eff8cd1b1b09 Mon Sep 17 00:00:00 2001 From: Jamie Hill Date: Mon, 28 Jun 2010 18:26:24 +0100 Subject: [PATCH] Allow a symbol to be supplied to redirect_to, following the render convention whereby it assumes an action --- .../lib/action_controller/metal/redirecting.rb | 2 + actionpack/test/controller/redirect_test.rb | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index b5f1d23..1c58276 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -83,6 +83,8 @@ module ActionController when :back raise RedirectBackError unless refer = request.headers["Referer"] refer + when Symbol + url_for(:action => options) else url_for(options) end.gsub(/[\r\n]/, '') diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 441bc47..3a53af1 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -57,6 +57,14 @@ class RedirectController < ActionController::Base def redirect_to_back_with_status redirect_to :back, :status => 307 end + + def redirect_to_action + redirect_to :custom_action + end + + def redirect_to_action_with_status + redirect_to :custom_action, :status => 307 + end def host_redirect redirect_to :action => "other_host", :only_path => false, :host => 'other.test.host' @@ -179,6 +187,19 @@ class RedirectTest < ActionController::TestCase assert_response :redirect assert_redirected_to :action => "other_host", :only_path => false, :host => 'other.test.host' end + + def test_redirect_to_action + get :redirect_to_action + assert_response :redirect + assert_redirected_to :action => "custom_action" + end + + def test_redirect_to_action_with_status + get :redirect_to_action_with_status + assert_response :redirect + assert_redirected_to :action => "custom_action" + assert_response 307 + end def test_module_redirect get :module_redirect -- 1.6.4.1