我是一位ROR新手,正在阅读Micheal Hartl的教程。我已经按照教程的每一个步骤,并坚持与路线有关的错误。我已经通过了我所有的代码,并尝试从谷歌的所有解决方案。长话短说我试图让测试通过。路由错误没有路由匹配{:action =>“/”,:controller =>“static_pages”}
这里是我的routes.rb
Rails.application.routes.draw do
root 'static_pages#home'
get '/help', to: 'static_pages#help'
end`
以下是错误的描述
1)Error
StaticPagesControllerTest#test_should_get_home: ActionController::UrlGenerationError: No route matches {:action=>"/", :controller=>"static_pages"} test/controllers/static_pages_controller_test.rb:10: in block in class:StaticPagesControllerTest'
2) Error
StaticPagesControllerTest#test_should_get_help: ActionController::UrlGenerationError: No route matches {:action=>"/help", :controller=>"static_pages"} test/controllers/static_pages_controller_test.rb:16:in `block in class:StaticPagesControllerTest'
这里是我的耙路线看起来像
root GET/ static_pages#home
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
我已经试过
root 'static_pages#home'
get '/static_pages/help', to: 'static_pages#help'
或
root 'static_pages#home'
match '/help', :to => 'static_pages#help', via: [:get]
但我仍然解决不了问题。我一直在盯着这个代码和错误几天。请帮忙。
*编辑,包括测试
test "should get home" do
get root_path
assert_response :success
assert_select "title", "Home | #{@base_title}"
end
test "should get help" do
get help_path
assert_response :success
assert_select "title", "Help | #{@base_title}"
end
rails -v 4.1.10; ruby -v 2.1.5p273 – Yoda
第一个错误是'{:action =>“/”,:controller =>“static_pages”}'。注意动作(即控制器中定义的*方法*)是'/'。看起来你的行为被命名为“家”和“帮助”。如果您发布测试,我们将能够告诉您更多信息。 –
添加了测试,Greg – Yoda