配置中出现RoR SendGrid错误,不允许部署到Heroku;第10章哈特尔

时间:2015-10-15 15:11:22

标签: ruby-on-rails heroku railstutorial.org sendgrid

我已经为SendGrid完成了教程的这一部分配置,搜索了大量的答案,在尝试推送到heroku时仍然出现此错误:

NameError: undefined local variable or method `auto' for #<SampleApp::Application:0x007f5c8bdaef78>

抛出错误的一行:

:enable_starttls_auto => true

来自config / environments.rb的完整代码:

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  host = 'gentle-sands-4285.herokuapp.com'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

非常感谢任何帮助,并希望通过本教程学习其他人。

1 个答案:

答案 0 :(得分:0)

请尝试将此文件添加到config / environments /文件夹中,而不是将其添加到config / environment.rb文件中。这是我做的:

我将此添加到我的config / environments / production.rb:

  config.action_mailer.default_url_options = { :host => 'YOUR_APP.herokuapp.com' }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
    address: ENV["SMTP_ADDRESS"],
    port: 587,
    domain: ENV["EMAIL_DOMAIN"],
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["EMAIL_USERNAME"],
    password: ENV["EMAIL_PASSWORD"]
  }

这是我的config / environments / development.rb:

config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: ENV["SMTP_ADDRESS"],
    port: 587,
    domain: ENV["EMAIL_DOMAIN"],
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["EMAIL_USERNAME"],
    password: ENV["EMAIL_PASSWORD"]
  }