3

在10.3.1 访问控制中测试有问题:

    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'?我不知道该怎么办。

4

1 回答 1

2

你的线resources :microposts, only: [:create, :destroy]routes.rb吗?查看代码清单 10.22

这将创建两个命名路由,microposts_path(可通过POST请求访问)和micropost_path(可通过请求访问),如果您在控制台中DELETE键入,您可以看到(以及应用程序中的所有其他路径) 。rake routes

查看本教程的表 7.1 - 这就是添加resources :usersroutes.rb.

Resources :microposts, only: [:create, :destroy]将以相同的方式工作,当然,除了你只会得到createanddestroy动作,如表 10.2中所述。

于 2013-08-20T03:11:49.307 回答