【发布时间】:2020-01-22 18:43:45
【问题描述】:
鉴于这个人为的例子:
RSpec.describe City::Road::HouseController, type: :controller do
let(:house) { create :house }
describe 'index' do
context 'a request is received without a valid basic-auth header' do
it 'renders unauthorized' do
before { method_that_unsets_basic_auth_header }
get(:index, params: { house_id: house.id })
expect(response).to have_http_status(:unauthorized)
end
end
end
end
使用以下路线:
namespace :city do
namespace :road do
resources :location, only: %i[show index] do
resources :house, only: %i[index], on: :member
end
end
end
为什么我总是收到这个错误?:
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"city/road/house :house_id=>1}
我认为这是因为它忽略了location。
我希望路线是:
/city/road/location/:location_id/house
我查看了以下问题/答案,但没有一个有帮助(尽管我承认我可能遗漏了一些东西):
【问题讨论】:
-
您希望这条路线究竟是什么?
-
啊,哎呀,谢谢你的收获!
标签: ruby rspec rspec-rails ruby-on-rails-6