caxlsx / caxlsx_rails

A Rails plugin to provide templates for the axlsx gem
MIT License
743 stars 84 forks source link

Rails 5 + Mailer: MissingTemplate Error #65

Open jonbcampos opened 7 years ago

jonbcampos commented 7 years ago

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 commented 7 years ago

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

straydogstudio commented 7 years ago

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

Is this running through Resque?

jonbcampos commented 7 years ago

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 notifications@github.com 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

jonbcampos commented 7 years ago

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

straydogstudio commented 7 years ago

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

jonbcampos commented 7 years ago

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 notifications@github.com 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

straydogstudio commented 7 years ago

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

jonbcampos commented 7 years ago

same error with downgrade

jonbcampos commented 7 years ago

@straydogstudio any other ideas?

straydogstudio commented 7 years ago

@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 commented 7 years ago

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" notifications@github.com 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 .

straydogstudio commented 7 years ago

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

jonbcampos commented 7 years ago

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 commented 7 years ago

Old issue but here's a fix:

mail(to: 'test@test.com', subject: "Export") do |f|
  f.text do
    render text: nil # In order to don't use a template
  end
end
straydogstudio commented 7 years ago

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

couraudt commented 7 years ago

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

rails (5.0.2)
axlsx (2.1.0.pre)
axlsx_rails (0.5.1)
elisoncampos commented 7 years ago

+1

kakoni commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Same issue.