我正在尝试在我的RoR应用程序中使用devise gem。它工作正常,除了在生产模式下我无法接收忘记密码的电子邮件。该页面显示以下错误:
Errno::ECONNREFUSED in Devise::PasswordsController#create
Connection refused - connect(2)
Rails.root: /app
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"S8rQE7SyT4+7gLvwIiFG+violKPAhzzKMZKUiH0xUSU=",
"user"=>{"email"=>"myemail@whatever.com"},
"commit"=>"Send me reset password instructions"}
我应该提到:
heroku[router]: at=info method=POST path="/users/password" host=myappname.herokuapp.com request_id =7e327911-49cb-448a-aa33-13f4bda8c3f dyno=web.1 connect=2ms service=351ms status=500 bytes=1754
production.rb 中的邮件程序配置与 development.rb 中的相同:
config.action_mailer.delivery_method = :smtp
# change to true to allow email to be sent during development
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: ENV["MAIL_ADDRESS"],
port: 587,
user_name: ENV["MAIL_USERNAME"],
password: ENV["MAIL_PASSWORD"]
}
此外,在 production.rb 中,我有:
config.action_mailer.default_url_options = { :host => 'myappname.herokuapp.com'}
在 development.rb 中我有:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
database.yml 文件如下所示:
default: &default
adapter: postgresql
user: <%= ENV['DB_USER'] %>
password: <%= ENV['DB_PASSWORD'] %>
pool: 5
timeout: 5000
port: 5432
development:
<<: *default
database: <%= ENV['DB_NAME_DEV'] %>
test:
<<: *default
database: <%= ENV['DB_NAME_TEST'] %>
production:
<<: *default
database: <%= ENV['DB_NAME_PROD'] %>
答案 0 :(得分:0)
终于明白了。
我使用Figaro gem来存储我的环境数据,但是这些密钥即使在开发中可用,也必须为heroku显示。只有在这个额外步骤之后,它们才能用于生产:
$ figaro heroku:set
或者,您可以使用以下方法设置这些变量:
$ heroku config:add <key>=<value>