加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 路由测试失败:NoMethodError:“/ the / rout

发布时间:2020-12-17 02:43:14 所属栏目:百科 来源:网络整理
导读:我得到了一个失败的测试,我调试很困难. 我的测试用例是: it "routes to #active" do get ("/parties/active").should route_to("parties#active")end 我的路线是: resources :parties do get 'active',:on = :collectionend 当我运行测试用例时,我收到以下
我得到了一个失败的测试,我调试很困难.

我的测试用例是:

it "routes to #active" do
  get ("/parties/active").should route_to("parties#active")
end

我的路线是:

resources :parties do
  get 'active',:on => :collection
end

当我运行测试用例时,我收到以下错误:

NoMethodError: undefined method `values' for "/parties/active":String

完整错误输出:https://gist.github.com/1748264

当我运行rake路线时,我看到:

active_parties GET    /parties/active(.:format)   parties#active
       parties GET    /parties(.:format)          parties#index
               POST   /parties(.:format)          parties#create
     new_party GET    /parties/new(.:format)      parties#new
    edit_party GET    /parties/:id/edit(.:format) parties#edit
         party GET    /parties/:id(.:format)      parties#show
               PUT    /parties/:id(.:format)      parties#update
               DELETE /parties/:id(.:format)      parties#destroy
          root        /                           parties#show

我正在运行的测试几乎与脚手架生成的测试相同:

it "routes to #new" do
  get("/parties/new").should route_to("parties#new")
end

知道发生了什么事吗?

解决方法

你在get和方法的参数之间放了一个空格.不要那样做.

你有这个:

it "routes to #active" do
  get ("/parties/active").should route_to("parties#active")
end

什么时候应该这样:

it "routes to #active" do
  get("/parties/active").should route_to("parties#active")
end

否则它会像这样评估:

get(("/parties/active").should route_to("parties#active"))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读