Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5 + Mailer: MissingTemplate Error #65

Open
jonbcampos opened this issue Jan 11, 2017 · 20 comments
Open

Rails 5 + Mailer: MissingTemplate Error #65

jonbcampos opened this issue Jan 11, 2017 · 20 comments

Comments

@jonbcampos
Copy link

jonbcampos commented Jan 11, 2017

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?

@jonbcampos
Copy link
Author

And I've tests calling the endpoint directly and I get the xlsx download no problem

@straydogstudio
Copy link
Collaborator

Have you tried: self.instance_variable_set(:@_lookup_context, nil) after you set your attachment?

Is this running through Resque?

@jonbcampos
Copy link
Author

jonbcampos commented Jan 11, 2017 via email

@jonbcampos
Copy link
Author

I just tested in the email preview and I get the same error (just an fyi)

@straydogstudio
Copy link
Collaborator

What are your versions of rails, axlsx, axlsx_rails, and rubyzip?

@jonbcampos
Copy link
Author

jonbcampos commented Jan 11, 2017 via email

@straydogstudio
Copy link
Collaborator

Would you try 0.4.0? It will throw some deprecations, but should still work with Rails 5.

@jonbcampos
Copy link
Author

same error with downgrade

@jonbcampos
Copy link
Author

@straydogstudio any other ideas?

@straydogstudio
Copy link
Collaborator

@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.

@jonbcampos
Copy link
Author

jonbcampos commented Jan 13, 2017 via email

@straydogstudio
Copy link
Collaborator

@jonbcampos Did you get anywhere with this? Have you tried passing layout: false to render to string?

@jonbcampos
Copy link
Author

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

@couraudt
Copy link

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

@straydogstudio
Copy link
Collaborator

@sweetdub Thanks for the note. What versions of rails/axlsx/axlsx_rails are you using?

@couraudt
Copy link

You're welcome @straydogstudio! I'm using those versions:

rails (5.0.2)
axlsx (2.1.0.pre)
axlsx_rails (0.5.1)

@elisoncampos
Copy link

+1

@kakoni
Copy link

kakoni commented Nov 8, 2017

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.

@abadfish
Copy link

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.

@hcyildirim
Copy link

Same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants