caxlsx_rails
caxlsx_rails copied to clipboard
Rails 5 + Mailer: MissingTemplate Error
I know this is showing up in other issues but, maybe I'm missing something, but in my tests I'm still getting an error:
Minitest::UnexpectedError: ActionView::MissingTemplate: Missing template layouts/mailer with {:locale=>[:en], :formats=>[:xlsx], :variants=>[], :handlers=>[:axlsx]}. Searched in:
* "/Users/myuser/Documents/code/myapp/app/views"
* "/Users/myuser/.rvm/gems/ruby-2.3.1/gems/pghero-1.6.2/app/views"
* "/Users/myuser/.rvm/gems/ruby-2.3.1/gems/resque-web-0.0.9/app/views"
* "/Users/myuser/.rvm/gems/ruby-2.3.1/gems/twitter-bootstrap-rails-3.2.2/app/views"
* "/Users/myuser/.rvm/gems/ruby-2.3.1/gems/devise_invitable-1.7.0/app/views"
* "/Users/myuser/.rvm/gems/ruby-2.3.1/gems/devise-4.2.0/app/views"
My code for the mailer:
def batch_transfer_complete(batch_transfer_id)
@batch_transfer = BatchTransfer.find(batch_transfer_id)
admins = Admin.pluck(:email)
xlsx = render_to_string
handlers: [:axlsx],
formats: [:xlsx],
template: 'batch_transfers/show',
locals: { batch_transfer: @batch_transfer }
attachments[@batch_transfer.to_filename] = { mime_type: Mime::XLSX, content: xlsx, encoding: 'base64' }
mail to: admins,
subject: t('admin_mailer.batch_transfer_complete.subject', model: BatchTransfer.model_name.human.titleize)
end
Any ideas of what I may be missing?
And I've tests calling the endpoint directly and I get the xlsx download no problem
Have you tried: self.instance_variable_set(:@_lookup_context, nil)
after you set your attachment?
Is this running through Resque?
I didn't but I did now to answer you fully and yes I get the same error with the addition.
I am running with Resque but this is showing up in my MiniTest, I haven't even gotten to running it yet due to the error.
On Wed, Jan 11, 2017 at 10:28 AM, Noel Peden [email protected] wrote:
Have you tried: self.instance_variable_set(:@_lookup_context, nil) after you set your attachment?
Is this running through Resque?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/straydogstudio/axlsx_rails/issues/65#issuecomment-271916624, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIgzX0hd0BrV0vkhA7EruDtGmUdB6iFks5rRQMSgaJpZM4LgvO9 .
-- Jonathan Campos
I just tested in the email preview and I get the same error (just an fyi)
What are your versions of rails, axlsx, axlsx_rails, and rubyzip?
axlsx_rails (0.5.0) rubyzip (1.1.7) axlsx (2.1.0.pre) rails (5.0.1)
On Wed, Jan 11, 2017 at 2:22 PM, Noel Peden [email protected] wrote:
What are your versions of rails, axlsx, axlsx_rails, and rubyzip?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/straydogstudio/axlsx_rails/issues/65#issuecomment-271983074, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIgzcYd_VbBsPILdlNW0URK07GZLPCoks5rRToSgaJpZM4LgvO9 .
-- Jonathan Campos
Would you try 0.4.0? It will throw some deprecations, but should still work with Rails 5.
same error with downgrade
@straydogstudio any other ideas?
@jonbcampos Unfortunately no. Not without me trying to get the same error and chasing it down. If you have time to set up a repo that reproduces this code, I can do it. Otherwise it may be a while.
I've tried to find this error and so far not had any luck. It's an odd one that started with Rails 4. They made changes with the layout context. I will try to spend some time in the next week digging on the error.
I'll see what I can do to create a paired down setup in the meantime.
On Jan 13, 2017 5:44 PM, "Noel Peden" [email protected] wrote:
@jonbcampos https://github.com/jonbcampos Unfortunately no. Not without me trying to get the same error and chasing it down. If you have time to set up a repo that reproduces this code, I can do it. Otherwise it may be a while.
I've tried to find this error and so far not had any luck. It's an odd one that started with Rails 4. They made changes with the layout context. I will try to spend some time in the next week digging on the error.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/straydogstudio/axlsx_rails/issues/65#issuecomment-272578068, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIgzXdD4XCefr23PR_ojPatnnEsc_T4ks5rSAxNgaJpZM4LgvO9 .
@jonbcampos Did you get anywhere with this? Have you tried passing layout: false
to render to string?
I believe I had tried it. In the end we ended up (for other reasons) just switching to CSV so I dropped the effort. I know that isn't great for you but that is where it is
Old issue but here's a fix:
mail(to: '[email protected]', subject: "Export") do |f|
f.text do
render text: nil # In order to don't use a template
end
end
@sweetdub Thanks for the note. What versions of rails/axlsx/axlsx_rails are you using?
You're welcome @straydogstudio! I'm using those versions:
rails (5.0.2)
axlsx (2.1.0.pre)
axlsx_rails (0.5.1)
+1
With Rails 5.1 also seeing this Missing template error. As a quick fix I renamed my view from index.xls.axlsx to index.axlsx.
Thank you so much @couraud this error has had me pulling my hair out all day! Workaround or not, this has my attachment sending with actual data. Same versions btw.
Same issue.