【发布时间】:2019-11-29 06:29:07
【问题描述】:
在测试我的控制器操作时,我收到此路由错误。我无法弄清楚我做错了什么
路线
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', to: 'user_posts#index', param: :user_type, constraints: {user_type: lambda { |req| ['abc', 'def'].include?(req.params["user_type"]) } }, as: :custom_posts
【问题讨论】:
标签: ruby-on-rails ruby rspec routing ruby-on-rails-5.2