Ruby on rails 控制器测试中的Rails路由问题
我不知道我在这里做错了什么。有人有什么见解吗 这是我的路线Ruby on rails 控制器测试中的Rails路由问题,ruby-on-rails,ruby-on-rails-3,unit-testing,routes,Ruby On Rails,Ruby On Rails 3,Unit Testing,Routes,我不知道我在这里做错了什么。有人有什么见解吗 这是我的路线 resources :accounts do collection do get "search/:term/:offset/:limit.:format", :action => "search", :constraints => { :offset => /\d+/, :limit => /\d+/ } end end 这是我的rake路由输出 GET /account
resources :accounts do
collection do
get "search/:term/:offset/:limit.:format", :action => "search", :constraints => { :offset => /\d+/, :limit => /\d+/ }
end
end
这是我的rake路由输出
GET /accounts/search/:term/:offset/:limit.:format {:offset=>/\d+/, :action=>"search", :controller=>"accounts", :limit=>/\d+/}
这是我的测试线
get :search, :term => "Test", :offset => 0, :limit => 2
这是我的错误
ActionController::RoutingError: No route matches {:term=>"Test", :action=>"search", :controller=>"accounts", :offset=>0, :limit=>2}
有什么想法吗
提前谢谢 我发现了问题
1) 它希望在字符串上匹配,因此
:offset => 0, :limit => 2
应该是
:offset => '0', :limit => '2'
2) :格式不是可选的。我选择将其作为可选参数,但如果遇到此问题,如果不将其设置为可选,则必须传递格式