rails-config-mailer默认url选项未生效(开发环境)



我正在调整创建的邮件中出现的url

<%= controller_url %>

但是当我用以下命令更改默认值时

config.action_mailer.default_url_options = { :host => "example.com", :protocol => 'https', :subdomain => "www"}

url作为保持不变

http://localhost:8000/controller

这不起作用的可能原因是什么?我在我的项目文件夹中仔细查找了可能定义主机或子域的地方,但一无所获。

编辑:似乎我需要在做出更改后重新启动服务器。

我不知道你是怎么想的,但我可以展示我的文件与你的文件进行比较。

所以我的开发文件是/config/environments/development.rb

config.consider_all_requests_local = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

我的生产文件是/config/environments/production.rb

config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => "https://example.com" } #=> Or https://www.example.com
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:user_name => ENV['USERNAME'],
:password => ENV['PASSWORD'],
:domain => 'example.com',
:address => 'smtp.example.net',
:port => 321,
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.delivery_method = :smtp

它运行得很好。

记住这些:

  • 只有当项目是一种开发模式时,开发文件才能工作
  • 只有当项目为生产模式时,生产文件才能工作
  • 并确保在更改上与配置相关的任何内容后重新启动服务器

您可以在发送邮件时检查日志发生了什么,对于生产运行,请遵循以下命令rails server -e production

最新更新