在测试控制器动作时,出现此路由错误。我无法弄清楚我做错了什么地方
路线
get ':user_type',to: 'user_posts#index',param: :user_type,constraints: lambda { |req| ['abc','def'].include?(req.params["user_type"]) },as: :custom_posts
规格:
describe "GET #index: enabled" do
it "returns http success" do
get :index,params: {user_type: 'abc'}
expect(response).to have_http_status(:success)
end
end
错误:
actionController::UrlGenerationError:
No route matches {:action=>"index",:controller=>"user_posts"}
此外,我通过更改路线在github上尝试了一种解决方案,但这对我不起作用
get ':user_type',constraints: {user_type: lambda { |req| ['abc','def'].include?(req.params["user_type"]) } },as: :custom_posts