Ruby on rails Rails控制器测试,当url路径不存在时';不匹配控制器路径
我的路线中有这个。rb:Ruby on rails Rails控制器测试,当url路径不存在时';不匹配控制器路径,ruby-on-rails,ruby-on-rails-4,controller,routing,Ruby On Rails,Ruby On Rails 4,Controller,Routing,我的路线中有这个。rb: get "user/:id" => "game_week#show_all" 控制器保存在app/controllers/game_week_controller.rb中 现在,我尝试调用这个方法,在game_week_controller_test.rb中: test "call rejected if user if user doesn't exist" do post :show_all, user_id: 10 assert_response
get "user/:id" => "game_week#show_all"
控制器保存在app/controllers/game_week_controller.rb中
现在,我尝试调用这个方法,在game_week_controller_test.rb中:
test "call rejected if user if user doesn't exist" do
post :show_all, user_id: 10
assert_response :not_found
end
这将抛出错误:
ActionController::UrlGenerationError: No route matches {:user_id=>"10", :controller=>"game_week", :action=>"show_all"}
我不知道这些是怎么形成的。它不可能是在寻找“游戏周”节目。因此,它必须寻找/游戏周/表演周作为一条路线。如何确保我从game\u week\u controller\u test.rb发布给用户/:id?您已经定义了
get
路线,但是您已经从规范中调用了post
:
使用以下命令:
get :show_all, id: 10
另外,请注意,参数是
id
而不是user\u id
是的,没错。如果我不想选择这个作为你的答案,出于尴尬,我会删除这个问题:)