Heroku-运行rails app不发送邮件而不显示错误

时间:2015-11-27 13:29:54

标签: ruby-on-rails ruby heroku actionmailer

我有一个Rails应用程序 并且我有一个表格,在提交后发送邮件

生产设置

production.rb

  config.eager_load = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { :host => 'jobzgoform.herokuapp.com'}
  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_mailer.raise_delivery_errors = true
  config.action_controller.perform_caching = true
  config.action_mailer.delivery_method = :smtp
  # SMTP settings for gmail
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "gmail.com",
      :user_name            => 'mygmailid',
      :password             => 'mygmailpassword',
      :authentication       => "plain",
      :enable_starttls_auto => true
  }

form_mailer.rb

class FormMailer < ApplicationMailer
 def registration_mail(form)
  mail(to: form.email, subject: 'JobzGo Registration')
 end
end

forms_controller.rb

def create
  @form = Form.create(form_params)
    if @form.save
      FormMailer.registration_mail(@form).deliver
      redirect_to forms_path
    end
  end

在heroku上运行它在提交表单后显示错误我在数据库中接收数据但是然后它在页面上生成错误并且没有发送邮件。在我得到的日志中

2015-11-27T13:19:43.550779+00:00 heroku[router]: at=info method=POST path="/forms" host=jobzgoform.herokuapp.com request_id=9943fd5e-a5f9-40cf-8f85-b6fd4cee59f0 fwd="182.71.29.59" dyno=web.1 connect=1ms service=685ms status=500 bytes=1683
2015-11-27T13:19:43.852960+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=jobzgoform.herokuapp.com request_id=6b6d904b-7c0e-4cc1-8219-a6cc3bd77d31 fwd="182.71.29.59" dyno=web.1 connect=0ms service=1ms status=200 bytes=157

无法调试,因为我没有收到任何错误

请帮助!!

1 个答案:

答案 0 :(得分:1)

请在Gemfile中添加rails_12factor gem(它有助于在Heroku上调试/ better_error_visibility)以进行生产。

请参阅Heroku日志。概率是你能够自己找出解决方案。

您也可以运行rails server -e production在本地的生产环境中运行。

希望它有所帮助!