ruby-on-rails - rails config mailer default url选项没有生效(开发环境)

标签 ruby-on-rails linux server localhost host

我正在调整出现在使用以下方法创建的邮件程序中的 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/

相关文章:

ruby-on-rails - TimeDate 方法检查返回 nil

ruby-on-rails - 无法让我的 ruby​​ on rails 项目创建数据库

ruby-on-rails - Stripe - 检查客户是否存在

android - 通过私有(private) channel 分发 Android 版本的最佳方式

javascript - 不需要在后台验证密码确认和密码吗?

javascript - 仅在带有 importmap 的 Rails 7 中将 Javascript 放置在一页中的位置

linux - 如果 dhcp 失败,设置保存的静态 IP 地址

linux - 在文件内容中搜索单词和日期 - shell 脚本

linux - 如何将嵌套命令传递给 ssh 在命令行中运行?

我不能生成一个新线程来处理新的 UDP "connection"吗?