我需要在SQL查询完成后呈现一个Excel模板。SQL需要3-4分钟才能完成。因此,我在ActiveJob中实现了SQL执行和excel模板渲染。
我将模板命名为my_template,如下所示:
class RefreshReportDataJob < ApplicationJob
include SuckerPunch::Job
queue_as :default
def perform
# <- Run a SQL first here ->
# After SQL above is complete, render an Excel template
ApplicationController.renderer.render(
:file => 'my_controller/my_template', :formats => [:xlsx, :html]
)
end此模板存在于views/my_controller/中。此模板呈现3个部分_my_partial1, _my_partial2, _my_partial3 -所有这些部分也存在于与my_template -> views/my_controller相同的文件夹中。
在渲染my_template时,我得到了这个错误:
ActionView::Template::Error Missing partial application/_my_partial1.xlsx.axlsx with {:locale=>[:en], :formats=>[:xlsx, :html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder, :axlsx]}. Searched in:
* "/home/ubuntu/workspace/rails/Mailer/my_app/app/views"如果Rails能够定位my_template,为什么它不能定位同一文件夹中的部分my_partial1呢?请帮帮我!
发布于 2019-05-13 22:33:23
问题是您调用的是ApplicationController.render。这将导致Rails在application/_your_partial中查找模板。
您必须将对render的调用更改为指向相应的控制器/视图模板。
因此,如果您的模板是app/views/my_controller/_my_partial格式的,则需要调用MyController.renderer.render(...)。
https://stackoverflow.com/questions/56114110
复制相似问题