2012-07-18 65 views
0

我想在路由级别(config/routes.rb)将campaigns#index重定向到newsletters#index如何在路由级别重定向,而不是在动作级别?

的config/routes.rb中

#match '/campaigns' => redirect('/newsletters')    # something like this 
resources :campaigns do 
    put 'send_preview' 
    put 'send_actual' 
    put 'unschedule' 
end 

以下测试成功,但再次,我希望它成功,由于路线级重定向,没有动作级重定向。

测试/功能/ campaigns_controller_test.rb

class CampaignsControllerTest < ActionController::TestCase 

test "get index should redirect to newsletters" do 
    get :index 
    assert_redirected_to newsletters_path 
end 

应用程序/控制器/ campaigns_controller.rb

一旦路线级重定向工作,我想摆脱这种行动:

def index 
    redirect_to newsletters_path 
end 
+0

'match'/ campaigns'=> redirect('/ newsletters')'是您如何从routes.rb重定向的方式。你在问什么? – 2012-07-18 21:01:41

+0

我不确定当时发生了什么问题,但是,我的评论栏确实有效。 – user664833 2012-08-01 23:28:27

回答

1

您的评论热线

match '/campaigns' => redirect('/newsletters') 

工作,也

match '/campaigns', to: 'newsletters#index' 

是工作压力太大。