我有以下路线规则:
get '/reports/stats_by_date', to: 'reports#stats_by_date'
耙路线给了我这个:
reports_stats_by_date GET /reports/stats_by_date(.:format) reports#stats_by_date
这看起来是正确的。所以我试图用这个函数从 rake 中测试我的控制器:
def test_reports_should_load
get :reports_stats_by_date, :start_date => '2013-10-01', :end_date => '2013-10-05', :format => :json
assert_response :success
end
很简单。但是当我运行 rake test 时,我收到以下错误:
ReportsControllerTest#test_reports_should_load:
ActionController::UrlGenerationError: No route matches {:start_date=>"2013-10-01", :end_date=>"2013-10-05", :format=>:json, :controller=>"reports", :action=>"reports_stats_by_date"}
test/controllers/reports_controller_test.rb:6:in `test_reports_should_load'
出于某种原因,Rails 试图在路由明确指向reports#stats_by_date 时加载操作:reports_stats_by_date。我在这里做错了什么?