ActionController :: RoutingError:没有路由匹配

时间:2013-03-12 07:48:34

标签: ruby-on-rails routing

我是铁轨的新手,所以请耐心等待。 我的测试出现了路由错误。测试如下:

require 'spec_helper'

describe "ProducerPages" do

  subject { page }

  describe "profile page" do
    @producer = Producer.create(name:"Example Producer", 
                             email: "producer@example.com", password: "foobar",
                             password_confirmation: "foobar")
    before { visit producer_path(@producer) }

    it { should have_selector('h1',    text: producer.name) }
    it { should have_selector('title', text: producer.name) }
  end
end

并且产生的失败是:

Failures:

  1) ProducerPages profile page
     Failure/Error: before { visit producer_path(@producer) }
     ActionController::RoutingError:
       No route matches {:action=>"show", :controller=>"producers", :id=>nil}
     # ./spec/requests/producer_pages_spec.rb:14:in `block (3 levels) in <top (required)>'

看起来,我在创建生成器实例变量时做错了。我试图使它成为一个普通变量,但后来我得到了这个错误:

  1) ProducerPages profile page
     Failure/Error: before { visit producer_path(producer) }
     ActionController::RoutingError:
       No route matches {:action=>"show", :controller=>"producers", 
     :id=>#<Producer id: nil, name: "Example Producer", 
     email: "producer@example.com", created_at: nil, updated_at: nil, 
     password_digest: "$2a$04$pXAEklj4nzYe48ojR5Ps/Oh8Ea9.QqKOajYBD2Rv0mQ9...", 
     remember_token: nil, admin: false, oid: nil, contact_name: nil, 
     street: nil, postal_code: nil, city: nil, country: nil, url: nil, 
     telephone: nil, cellular: nil, type: "Producer", producer_id: nil, 
     client_key: nil, product_count: 0>}
     # ./spec/requests/producer_pages_spec.rb:14:in `block (3 levels) in <top (required)>'

routes.rb文件包含

  resources :producers

我做错了什么?

0 个答案:

没有答案