我正在关注Michael Hartl的Rails教程,并且我已经设置为7.22而没有任何主要故障。Michael Hartl Rails教程第7章错误在UsersController中找不到动作
Failures:
1) UserPages signup with invalid information should not create a user
Failure/Error: expect{click_button submit }.not_to change(User, :count)
AbstractController::ActionNotFound:
The action 'create' could not be found for UsersController
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:29:in `block (5 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:29:in `block (4 levels) in <top (required)>'
2) UserPages signup with valid information should create a user
Failure/Error: expect{click_button submit}.to change(User, :count).by(1)
AbstractController::ActionNotFound:
The action 'create' could not be found for UsersController
# (eval):2:in `click_button'
# ./spec/requests/user_pages_spec.rb:42:in `block (5 levels) in <top (required)>'
# ./spec/requests/user_pages_spec.rb:42:in `block (4 levels) in <top (required)>'
Finished in 0.7718 seconds
6 examples, 2 failures
我已经添加了以下到我的用户控制器页面的指示通过教程:
,但它仍然没有按”不过我从测试的输出,说难住了t似乎工作。我试着加入了创建方法,但只是抛出回缺少模板错误...
在情况下,它可以帮助这里的耙路线命令的输出:
~/dev/rails/sample_app$ rake routes
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root / static_pages#home
signup /signup(.:format) users#new
help /help(.:format) static_pages#help
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact
在回应评论,测试失败的是:
describe "signup" do
before{ visit signup_path }
let(:submit) {"Create my account"}
describe "with invalid information" do
it "should not create a user" do
expect{click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect{click_button submit}.to change(User, :count).by(1)
end
end
end
在此先感谢您的任何意见!
我看到用户#创建路由,所以我猜测创建操作是在您的控制器中定义的? 发布适当的测试,可能是错别的地方 – TheIrishGuy
@ TheIrishGuy上面发布了失败的测试,谢谢 – TangoKilo
如果它抛出一个“缺少模板”的错误,那么你可能没有'create'模板。 –