簡體   English   中英

rails config mailer 默認 url 選項未生效(開發環境)

[英]rails config mailer default url options not taking effect (development environment)

我正在調整出現在創建的郵件中的 url,

<%= controller_url %>

但是當我使用以下命令更改默認值時

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

網址保持不變

http://localhost:8000/控制器

這不起作用的一些可能原因是什么? 我在我的項目文件夾中仔細查看了可能定義主機或子域的位置,但一無所獲。

編輯:似乎我需要在進行更改后重新啟動我的服務器。

我不知道您如何嘗試,但我可以展示我的文件以與您的文件進行比較。

所以我的開發文件是/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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM