简体   繁体   English

传递 rails 服务器域名以进行邮寄的最佳方式是什么?

[英]What's the best way to pass in the domain name of your rails server for mailing?

I have an app that has is up in a few environments ie (development, staging, beta, live)我有一个在几个环境中运行的应用程序,即(开发、登台、测试版、实时)

What's the best way to pass in an app's domain name when sending mail, to allow for different domain names depending on the server?发送邮件时传入应用程序域名的最佳方式是什么,以允许根据服务器使用不同的域名?

My first thought is to add something in the respective environment.rb files for each one, so config/environments/beta.rb would contain我的第一个想法是在各自的 environment.rb 文件中为每个添加一些内容,因此config/environments/beta.rb将包含

ActionMailer::Base.smtp_settings[:domain] = 'beta.domain.com'

And config/environments/staging.rb would contain config/environments/staging.rb将包含

ActionMailer::Base.smtp_settings[:domain] = 'staging.domain.com'

This feels like I'm doing something so basic that Rails would already have this value lying around, but I haven't found it in any of the places I would normally expect, nor can i find it in the documentation.这感觉就像我在做一些非常基础的事情,以至于 Rails 已经有了这个值,但我没有在我通常期望的任何地方找到它,也没有在文档中找到它。

What's the best approach to take here?在这里采取的最佳方法是什么?

I usually just pass the value of request.host in to the ActionMailer method.我通常只是将request.host的值传递给 ActionMailer 方法。

In your environment files, you want to set:在您的环境文件中,您要设置:

ActionMailer::Base.default_url_options = { :host => "beta.domain.com" }

If you're using url_for instead of named routes, you also need to specify:only_path => false... so you don't get relative urls.如果您使用 url_for 而不是命名路由,您还需要指定:only_path => false... 这样您就不会获得相对 url。 I generally try to use named routes, however.但是,我通常尝试使用命名路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM