控制器测试中的 Rails 路线问题
我对自己在这里做错了什么感到茫然。有人有任何见解吗?
这是我的routes.rb
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}
有什么想法吗?
提前致谢!
I'm at a loss as to what I'm doing wrong here. Anyone have any insight?
Here's my routes.rb
resources :accounts do
collection do
get "search/:term/:offset/:limit.:format", :action => "search", :constraints => { :offset => /\d+/, :limit => /\d+/ }
end
end
Here's my rake routes output...
GET /accounts/search/:term/:offset/:limit.:format {:offset=>/\d+/, :action=>"search", :controller=>"accounts", :limit=>/\d+/}
Here's my test line...
get :search, :term => "Test", :offset => 0, :limit => 2
Here's my error...
ActionController::RoutingError: No route matches {:term=>"Test", :action=>"search", :controller=>"accounts", :offset=>0, :limit=>2}
Any ideas?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题...
1) 它期望在字符串上匹配,因此
应该是
2) :format 不是可选的。我选择将其设为可选参数,但如果遇到这种情况,如果不将其设为可选参数,则必须传递格式。
I found the issues...
1) It is expecting to match on strings so instead of
it should be
2) :format was not optional. I chose to make it an optional param, but if you encounter this you will have to pass format along if you don't make it optional.