【发布时间】:2016-04-07 06:29:11
【问题描述】:
我通过对生产服务器使用 fork 命令创建了新的暂存环境。现在对于用户注册,我向用户发送了邮件进行身份验证,现在对于登台服务器,我如何更改该邮件 url。就我而言,暂存服务器邮件地址仍然是我的生产服务器。
【问题讨论】:
标签: ruby-on-rails ruby git heroku
我通过对生产服务器使用 fork 命令创建了新的暂存环境。现在对于用户注册,我向用户发送了邮件进行身份验证,现在对于登台服务器,我如何更改该邮件 url。就我而言,暂存服务器邮件地址仍然是我的生产服务器。
【问题讨论】:
标签: ruby-on-rails ruby git heroku
试试这个,
config.action_mailer.default_url_options = { host: "example.com" }
通过将 :host 选项设置为 config/application.rb 中的配置选项来设置将在所有邮件程序中使用的默认主机,请参阅此链接 (http://api.rubyonrails.org/classes/ActionMailer/Base.html)
【讨论】:
ENV,请参阅此链接它应该对您有所帮助(richonrails.com/articles/creating-a-custom-rails-environment)
您可以创建文件:config/initializers/action_mailer.rb,其内容如下:
# config/initializers/action_mailer.rb
if Rails.env.development?
# Settings for mailcatcher on dev enviroment
Rails.application.config.action_mailer.tap do |action_mailer|
action_mailer.default_url_options = {
host: 'dev-domain.dev',
port: 3000
}
action_mailer.delivery_method = :smtp
action_mailer.perform_deliveries = true
action_mailer.raise_delivery_errors = false
action_mailer.smtp_settings = { address: "localhost", port: 1025 }
end
end
if Rails.env.production?
# Define settings for Production SMTP Server
Rails.application.config.action_mailer.tap do |action_mailer|
action_mailer.default_url_options = {
host: 'production-domain.com'
}
action_mailer.delivery_method = :smtp
action_mailer.perform_deliveries = true
action_mailer.raise_delivery_errors = true
action_mailer.smtp_settings = {
address: 'mail.server.com',
port: '465',
authentication: :plain,
user_name: 'noreply@production-domain.com',
password: '',
domain: 'production-domain.com',
enable_starttls_auto: false,
ssl: true
}
end
end
if Rails.env.staging?
# Define settings for Staging SMTP Server
Rails.application.config.action_mailer.tap do |action_mailer|
action_mailer.default_url_options = {
host: 'staging-domain.com'
}
action_mailer.delivery_method = :smtp
action_mailer.perform_deliveries = true
action_mailer.raise_delivery_errors = true
action_mailer.smtp_settings = {
address: 'mail.staging-server.com',
port: '465',
authentication: :plain,
user_name: 'noreply@staging-domain.com',
password: '',
domain: 'staging-domain.com',
enable_starttls_auto: false,
ssl: true
}
end
end
【讨论】:
您可以按照here 的说明为应用程序的 URL 使用环境变量,例如APPLICATION_URL = 'http://foo.herokuapp.com' 在生产环境中和 APPLICATION_URL = 'http://foo-staging.herokuapp.com' 在暂存环境中。然后,您可以通过在代码中使用这些环境变量,在不同的环境中使用不同的 URL。
【讨论】: