Ruby on rails Rails--到路径帮助程序的命名空间路由

Ruby on rails Rails--到路径帮助程序的命名空间路由,ruby-on-rails,routes,Ruby On Rails,Routes,我有以下路线规则: get '/reports/stats_by_date', to: 'reports#stats_by_date' rake routes告诉我: 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', to: 'reports#stats_by_date'
rake routes告诉我:

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测试时,我得到以下错误:

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(按日期)时,reports(按日期)stats(按日期)。我在这里做错了什么?

我认为这是因为您只需要引用操作名,而不需要引用路径名。按日期统计数据,而不是按日期报告统计数据

 def test_reports_should_load    
  get :stats_by_date, :start_date => '2013-10-01', :end_date => '2013-10-05', :format => :json
  assert_response :success
end

在您的测试中,您应该加载try get“/reports/stats\u by\u date”,:start\u date=>'2013-10-01',:end\u date=>'2013-10-05',:format=>:json。get通常希望动作名称作为符号,而不是助手方法。让我知道这是否有效。现在我没有路线匹配了…:action=>“reports/stats\u by\u date”那么这肯定会起作用get:stats\u by\u date、:start\u date=>“2013-10-01”、:end\u date=>“2013-10-05”、:format=>:json。现在,我给的是动作名称而不是Pathk,这是可行的。有人能给我解释一下Rails如何处理不同名称空间下的两条冲突路由吗?例如,/reports/stats\u by\u date vs/charts/stats\u by\u date。