【发布时间】:2012-07-18 04:13:44
【问题描述】:
我想在路由级别 (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
app/controllers/campaigns_controller.rb
一旦路由级重定向工作,我想摆脱这个动作:
def index
redirect_to newsletters_path
end
【问题讨论】:
-
match '/campaigns' => redirect('/newsletters')是您从 routes.rb 进行重定向的方式。你在问什么? -
我不确定当时出了什么问题,但是是的,我的评论行确实有效。
标签: ruby-on-rails ruby-on-rails-3 testing redirect routes