“没有路线匹配”;错误? [英] "No route matches" error?

查看:93
本文介绍了“没有路线匹配”;错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Rspec新手,刚开始是在Rails 3上生成一个新的控制器。它默认会生成一些Rspec测试。我有一个关于如何使它们通过的问题。就目前而言,我在终端中看到该测试

I am new Rspec and just started by generating a new controller on Rails 3. It generates some Rspec tests by default. I have a question about how to make them pass though. As it stands, I see this test in my terminal"


1)BuildingsController GET'show'
应该成功

1) BuildingsController GET 'show' should be successful

 Failure/Error: get 'show'
 No route matches {:controller=>"buildings", :action=>"show"}
 # ./spec/controllers/buildings_controller_spec.rb:17:in `block (3 levels) in <top (required)>'


但是,我不明白为什么会这样,因为我已经创建了这条路线( resources:buildings ),然后我运行了耙路并确保它在那里。

However, I don't understand why it's coming up because I already have this route created ("resources :buildings"), and I ran rake routes and made sure it's there.


GET /buildings/:id(.:format){:action => show,:controller => buildings}

building GET /buildings/:id(.:format) {:action=>"show", :controller=>"buildings"}

通过此考试有什么必要?这是测试的方式:

What is necessary to make this pass? Here is the test by the way:

  describe "GET 'show'" do
    it "should be successful" do
      get 'show'
      response.should be_success
    end
  end


推荐答案

您需要传递现有建筑物的ID : get:show,:id => @ building.id

You need to pass id of existing building: get :show, :id => @building.id

路由对此有所抱怨,因为:id 不是可选的

Routes complain about it because :id isn't optional.

这篇关于“没有路线匹配”;错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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