2016-04-15 66 views
0

尝试实施通过gmail在生产(heroku)中发送电子邮件时,我感到头痛。当运行heroku logs我得到如下:尝试解决生产中的ActionView :: MissingTemplate(heroku)

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' 

这似乎是与模板的问题,但邮件模板目录layouts/mailer.html.erb

下面是代码的ActionMailer:

邮寄/ application_mailer.rb

class ApplicationMailer < ActionMailer::Base 
     default from: "Example <[email protected]>" 
     layout 'mailer' 
    end 

邮寄/ 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 

型号/ cadastro.rb

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

在deve一切正常。我错过或遗忘了什么?

+0

在'mailer.html.erb': ' <%= yield %> ' – Micael

回答

0

我不知道这是否是问题,但您不需要在邮件程序中指定格式。只要做到这一点:

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

这是从我通常可以看到的唯一区别。

+0

我所做的更改,不幸的是,我不断收到同样的错误日志中的Heroku。 – Micael

+0

我设法通过删除'application_controller.rb'的'layouts'mailer'来解决这个问题。它似乎不使用'mailer.html.erb'布局,而是'cliente_mailer.rb'的'boas_vindas.html.erb'。奇怪的是,这只发生在生产中,将环境的设置? – Micael

相关问题