【问题标题】:Trying solve ActionView::MissingTemplate in production (heroku)尝试在生产中解决 ActionView::MissingTemplate (heroku)
【发布时间】:2016-04-15 18:46:14
【问题描述】:

尝试在生产环境 (heroku) 中实现通过 gmail 发送电子邮件时,我感到很头疼。运行 heroku logs 时,我得到以下信息:

2016-04-15T18:20:47.117490+00:00 app[web.1]: ClienteMailer#boas_vindas: processed outbound mail in 5.8ms
2016-04-15T18:20:47.118282+00:00 app[web.1]:    (0.7ms)  ROLLBACK
2016-04-15T18:20:47.117474+00:00 app[web.1]: 
2016-04-15T18:20:47.118705+00:00 app[web.1]: Completed 500 Internal Server Error in 31ms (ActiveRecord: 6.5ms)
2016-04-15T18:20:47.120623+00:00 app[web.1]: ActionView::MissingTemplate (Missing template layouts/mailer with {:locale=>[:"pt-BR"], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
2016-04-15T18:20:47.120613+00:00 app[web.1]: 
2016-04-15T18:20:47.120624+00:00 app[web.1]:   * "/app/app/views"
2016-04-15T18:20:47.120625+00:00 app[web.1]:   app/mailers/cliente_mailer.rb:6:in `block (2 levels) in boas_vindas'
2016-04-15T18:20:47.120625+00:00 app[web.1]: ):
2016-04-15T18:20:47.120627+00:00 app[web.1]:   app/models/cadastro.rb:6:in `envia_email_boasvindas'
2016-04-15T18:20:47.120626+00:00 app[web.1]:   app/mailers/cliente_mailer.rb:5:in `boas_vindas'
2016-04-15T18:20:47.120626+00:00 app[web.1]:   app/mailers/cliente_mailer.rb:6:in `block in boas_vindas'
2016-04-15T18:20:47.120627+00:00 app[web.1]:   app/controllers/cadastros_controller.rb:18:in `create'

好像是模板有问题,但是mailer模板在layouts/mailer.html.erb目录下。

下面是 ActionMailer 的代码:

mailers/application_mailer.rb

class ApplicationMailer < ActionMailer::Base
      default from: "Example <example@gmail.com>"
      layout 'mailer'
    end

mailers/cliente_mailer.rb

class ClienteMailer < ApplicationMailer
    def boas_vindas cliente
        @cliente = cliente
        mail(:to => @cliente.email, :subject => 'Example.') do |format|
            format.html { render 'boas_vindas' }
        end
    end 
end

models/cadastro.rb

.
.
.
after_create :envia_email_boasvindas
def envia_email_boasvindas
    ClienteMailer.boas_vindas(self).deliver
end
.
.
.

在开发中一切正常。我错过了什么或忘记了什么?

【问题讨论】:

  • mailer.html.erb内:&lt;body&gt; &lt;%= yield %&gt; &lt;/body&gt;

标签: ruby-on-rails ruby heroku actionmailer


【解决方案1】:

我不知道这是否是问题,但您不需要在邮件中指定格式。去做吧:

class ClienteMailer < ApplicationMailer
    def boas_vindas cliente
        @cliente = cliente
        mail(:to => @cliente.email, :subject => 'Example.')
    end 
end

这是我能看到的与我通常做的唯一不同的地方。

【讨论】:

  • 我做了更改,不幸的是,我在 heroku 中不断收到相同的错误日志。
  • 我设法通过删除layouts 'mailer'application_controller.rb 解决了这个问题。它似乎不使用mailer.html.erb 布局,而是使用cliente_mailer.rbboas_vindas.html.erb。奇怪的是这只发生在生产中,会是环境设置吗?
猜你喜欢
  • 1970-01-01
  • 2019-12-21
  • 1970-01-01
  • 2011-05-14
  • 1970-01-01
  • 2014-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多