Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 控制器测试中的Rails路由问题_Ruby On Rails_Ruby On Rails 3_Unit Testing_Routes - Fatal编程技术网

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) :格式不是可选的。我选择将其作为可选参数,但如果遇到此问题,如果不将其设置为可选,则必须传递格式