Rails路线问题与控制器测试 [英] Rails routes issue with controller testing

查看:73
本文介绍了Rails路线问题与控制器测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我在这里做错了事不知所措。有人有见识吗?

I'm at a loss as to what I'm doing wrong here. Anyone have any insight?

这是我的路线。

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

这是我的错误...

ActionController::RoutingError: No route matches {:term=>"Test", :action=>"search", :controller=>"accounts", :offset=>0, :limit=>2}

有什么想法吗?

谢谢!

推荐答案

我发现了问题...

1)期望在字符串上匹配,所以不是

1) It is expecting to match on strings so instead of

:offset => 0, :limit => 2

应该是

:offset => '0', :limit => '2'

2):格式不是可选的。我选择将其设置为可选参数,但是如果遇到此问题,则必须将format传递给您,否则将其设为可选参数。

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.

这篇关于Rails路线问题与控制器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆