2013-08-19 86 views
3

有在10.3.1 Access control與測試問題:railstutorial 10.3.1:未定義的局部變量或方法`microposts_path '`micropost_path'

Failures: 

    1) Authentication authorization for non-signed-in users in the Microposts controller submitting to the destroy action 
Failure/Error: before { delete micropost_path(FactoryGirl.create(:micropost)) } 
NoMethodError: 
    undefined method `micropost_path' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_3::Nested_1::Nested_3::Nested_2:0x00000004edd970> 
# ./spec/requests/authentication_pages_spec.rb:117:in `block (6 levels) in <top (required)>' 

    2) Authentication authorization for non-signed-in users in the Microposts controller submitting to the create action 
Failure/Error: before { post microposts_path } 
NameError: 
    undefined local variable or method `microposts_path' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_3::Nested_1::Nested_3::Nested_1:0x0000000521c758> 
# ./spec/requests/authentication_pages_spec.rb:112:in `block (6 levels) in <top (required)>' 

routes.rb這個附加:

resources :misroposts, only: [:create, :destroy] 

但不幫忙。什麼意思undefined method 'micropost_path'?我不知道該怎麼辦。

回答

2

你是否在routes.rbresources :microposts, only: [:create, :destroy]?檢查出Listing 10.22

這將創建兩個命名路由,microposts_path(用POST要求訪問)和micropost_path,你可以看到(連同應用中的所有其他路徑),如果鍵入rake routes進(用DELETE要求訪問)安慰。

查看本教程的Table 7.1 - 這就是當您將resources :users添加到routes.rb時發生的情況。

Resources :microposts, only: [:create, :destroy]會的工作方式相同,不同之處,當然,你只會得到createdestroy行動,在Table 10.2解釋。

+0

對不起,我提出了其他問題。是的,我有'資源:misroposts,只:[:創建,:銷燬]'。 'rake routes' have paths: 'misroposts POST /misroposts(.:format)misroposts#create' 'misropost DELETE /misroposts/:id(.:format)misroposts#destroy' –

+0

哦,看起來你有一個錯字。它應該用'c而不是'misroposts'來表示'microposts'。 – najwa

+1

Facepalm!謝謝。 –

相關問題