我是一位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