0
我有一个叫做“newbie”的模型。在routes.rb中文件看起来像:rails route - undefined method
Myapp::Application.routes.draw do
resources :newbies
root to: 'static_pages#home'
match '/about', to: 'static_pages#about'
控制器是这样的:
class NewbiesController < ApplicationController
def show
@newbie = Newbie.find(params[:id])
end
......
end
当我写测试:
require 'spec_helper'
describe "Newbie pages" do
subject { page }
describe "profile page" do
let(:newbie) { FactoryGirl.create(:newbie) }
before { visit newbie_path(newbie)}
it { should have_selector('h1', text: newbie.name) }
it { should have_selector('title', text: newbie.name) }
end
end
它总是失败,说:
1) Newbie pages profile page
Failure/Error: before { visit newbie_path(newbie)}
NoMethodError:
undefined method `newbie_path' for # <RSpec::Core::ExampleGroup::Nested_2::Nested_2:0x007f97f7f33068>
# ./spec/requests/newbie_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
2) Newbie pages profile page
Failure/Error: before { visit newbie_path(newbie)}
NoMethodError:undefined method `newbie_path' for
我认为资源:新手会创建像newbie_path这样的辅助方法,但为什么它说未定义的方法?
感谢
ü可以发布的所有路由。通过耙路线 – sameera207 2012-04-17 05:51:44
哇,问题解决了。看起来像铁轨认为新手是newby而不是新手的复数newby_path作品...感谢提醒 – alexZ 2012-04-17 06:01:06