我有一个控制器/dashboard/sites_controller.rb
,在其中有一个动作attendance_summer_city_camp_integrativ
def attendance_summer_city_camp_integrativ
@site = Site.find(params[:site_id])
respond_to do |format|
format.xlsx
end
end
如您所见,它将返回一个Excel。
config/routes.rb
namespace :dashboard do
resources :sites do
get :attendance_summer_city_camp_integrativ
end
end
在我的测试文件中,当我对此地址进行获取请求时,我会得到
No route matches {:action=>"/dashboard/sites/24/attendance_summer_city_camp_integrativ.xlsx", :controller=>"dashboard/sites"}
describe 'GET #attendance_summer_city_camp_integrativ' do
subject do
get dashboard_site_attendance_summer_city_camp_integrativ_path(site.id, format: :xlsx)
end
end
Failure/Error: get dashboard_site_attendance_summer_city_camp_integrativ_path(site.id, format: :xlsx)
ActionController::UrlGenerationError:
No route matches {:action=>"/dashboard/sites/24/attendance_summer_city_camp_integrativ.xlsx", :controller=>"dashboard/sites"}
当我在浏览器中手动转到该地址时,它可以正常工作。
Started GET "/dashboard/sites/6/attendance_summer_city_camp_integrativ.xlsx" for 127.0.0.1 at 2019-06-28 18:18:46 +0200
Processing by Dashboard::SitesController#attendance_summer_city_camp_integrativ as XLSX
我在做什么错了?
答案 0 :(得分:0)
也许是这样:
TypeRep
应该更像这样:
describe 'GET #attendance_summer_city_camp_integrativ' do
subject do
get dashboard_site_attendance_summer_city_camp_integrativ_path(site.id, format: :xlsx)
end
end
(根据docs,我想您可能需要对Rails 5 v。pre-rails 5形成不同的参数。)
您有一个名为describe 'GET #attendance_summer_city_camp_integrativ' do
subject do
get attendance_summer_city_camp_integrativ, {site_id: site.id, format: :xlsx}
end
end
的{{1}},但是您的测试正在尝试调用操作action
。这不是动作,而是完整的网址。那么,可能是调用attendance_summer_city_camp_integrativ
而不是/dashboard/sites/24/attendance_summer_city_camp_integrativ.xlsx
了吗?