路由错误没有路由匹配{:action =>“/”,:controller =>“static_pages”}

时间:2017-02-28 14:01:00

标签: ruby-on-rails ruby routing rails-routing

我是一名正在阅读Micheal Hartl教程的ROR新手。我已经按照教程的每个步骤操作,并且我遇到了有关路线的错误。我已经完成了所有代码并尝试了谷歌的所有解决方案。长话短说我试图通过考试。

这是我的routes.rb

Rails.application.routes.draw do
root 'static_pages#home'
get '/help', to: 'static_pages#help'
end`

以下是错误说明

  

1)错误
StaticPagesControllerTest#test_should_get_home:   ActionController :: UrlGenerationError:没有路由匹配{:action =>“/”,:controller =>“static_pages”} test / controllers / static_pages_controller_test.rb:10:在类中的块:StaticPagesControllerTest'   
2)错误
StaticPagesControllerTest#test_should_get_help:   ActionController :: UrlGenerationError:没有路由匹配{:action =>“/ help”,:controller =>“static_pages”}   test / controllers / static_pages_controller_test.rb:16:在`类中的块:StaticPagesControllerTest'

以下是我的佣金路线的样子

  

root GET / static_pages #home   
帮助GET /help(.:format)static_pages #help   
关于GET /about(.:format)static_pages#about   
联系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

0 个答案:

没有答案