2012-04-17 15 views
0

私は "newbie"というモデルを持っています。 routes.rbをファイルには、次のようになります。railsルート - 未定義メソッド

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 

私はリソースと思う:newbiesはnewbie_pathのようなヘルパーメソッドを作成しますが、なぜそれは未定義メソッドと呼ばれますか?

おかげで初心者のためのリソース

+0

を使用する必要があります。レーキ経由で – sameera207

+0

うわー、問題解決。 Newbiesはnewbieの代わりにnewbyの複数であると思うレールのように見える..... newby_path works ...覚えてくれてありがとう – alexZ

答えて

0

あなたは すくいルートを実行

生成されたルートは、あなたが期待しているものとは全く異なるものです。

newbies GET /newbies(.:format) 
{:action=>"index", :controller=>"newbies"} 
     POST /newbies(.:format) 
{:action=>"create", :controller=>"newbies"} 

new_newby GET /newbies/new(.:format) 
{:action=>"new", :controller=>"newbies"} 

edit_newby GET /newbies/:id/edit(.:format) 
{:action=>"edit", :controller=>"newbies"} 

newby GET /newbies/:id(.:format) 
{:action=>"show", :controller=>"newbies"} 
PUT /newbies/:id(.:format) 
{:action=>"update", :controller=>"newbies"} 

DELETE /newbies/:id(.:format) 
{:action=>"destroy", :controller=>"newbies"} 

uはすべてのあなたのルートを投稿することができるように、あなたは

newby_path(newbie) 
+0

ええ、ちょうど同様に見つけた..ありがとう – alexZ

関連する問題