我正在關注Rails教程,並且我有幾個頁面正在添加一些測試。_path的用法給出了「沒有路由匹配..」錯誤
我想使用help_path代替:幫助我pages_controller_test:
test "should get help" do
get help_path
assert_response :success
assert_select "title", "Help | #{@base_title}"
end
我說在我的routes.rb文件中這一行:
get '/help', to: 'pages#help'
但我得到這個錯誤:
1) Error: PagesControllerTest#test_should_get_help: ActionController::UrlGenerationError: No route matches {:action=>"/help", :controller=>"pages"} test/controllers/pages_controller_test.rb:62:in `block in '
我已經嘗試了一些解決方案,但沒有一個解決了我的問題。 我也用這個行,而不是嘗試:
match '/home' => 'main_pages#home', :as => :home
但它也不能工作。
我的Rails的版本是:4.2.4 我的紅寶石版本是:紅寶石2.1.9p490(2016年3月30日修訂54437)x86_64的-Linux的GNU]
輸出$耙路線:
Prefix Verb URI Pattern Controller#Action
root GET/ pages#home
help GET /help(.:format) pages#help
courses GET /courses(.:format) pages#courses
programs GET /programs(.:format) pages#programs
schools GET /schools(.:format) pages#schools
dashboard GET /dashboard(.:format) pages#dashboard
profile GET /profile(.:format) pages#profile
account GET /account(.:format) pages#account
signout GET /signout(.:format) pages#signout
編輯: 我可以在我的html代碼中使用help_path ..等沒有任何問題,但在測試中,它給出了該錯誤。 謝謝:)
不要在你的路由定義斜槓(使用' 'help''和'' home''代替)。另外,運行'rake routes'查看所有路線。 – mmichael
你可以添加你的控制器和你的整個'routes.rb'嗎? –
@SebastiánPalma我的application_controller只有一個hello函數 –