我正在调整出现在使用以下方法创建的邮件程序中的 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
关于ruby-on-rails - rails config mailer default url选项没有生效(开发环境),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53112876/