这让我陷入了混乱。
我有一个失败的测试应该通过。我从第ActionController::UrlGenerationError: No route matches
行获得了无路由错误get :Show, params: {id: @team}
。我的应用程序中的其他所有内容都确认已定义路由~/teams/:id
,从confing/routes.rb
到开发服务器。
我的代码:
测试失败
test "should get show action when logged in" do
log_in_as(@other_user)
get :Show, params: {id: @team}
assert_response :success
assert_template 'teams/show'
end
错误
ActionController::UrlGenerationError: No route matches {:action=>"Show", :controller=>"teams", :id=>#<Team id: 1049939034, teamname: "Blue panthers" ..... >}
配置/ routes.rb中
resources :teams, only: [:show, :index]
Rake Routes
team GET /teams/:id(.:format) teams#show
Rails控制台
2.4.2 :011 > app.team_path(2)
=> "/teams/2"
开发服务器日志
Started GET "/teams/4" for 127.0.0.1 at 2018-04-30 21:30:51 -0400
Processing by TeamsController#show as HTML
Parameters: {"id"=>"4"}
User Load (23.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Team Load (16.4ms) SELECT `teams`.* FROM `teams` WHERE `teams`.`id` = 4 LIMIT 1
Rendering teams/show.html.erb within layouts/application
Completed 200 OK in 474ms (Views: 398.0ms | ActiveRecord: 48.6ms)
我没有关于如何调试此错误的想法。