铁轨和设计:如何自动配置域名邮件?

发布于 2025-01-01 01:57:23 字数 871 浏览 0 评论 0原文

我需要一些有关在生产 Ruby-on-Rails 站点中配置邮件的建议。

我在 EngineYard 上部署 Rails 应用程序。我有几个网站,例如 demo.mydomain.comstaging.mydomain.com - 如何配置 Devise,以便在部署时我可以确保收到确认邮件自动来自 demo.mydomain.comstaging.mydomain.comie,我想要相同的 GitHub 代码库,并且想要动态填充配置。

目前在 config/environments/production.rb 中,我有以下行:

config.action_mailer.default_url_options = { :host => 'demo.mydomain.com' }

但是,当将相同的代码部署到 staging.mydomain.com 时,这是不正确的,因为它们都在 RAILS_ENV=生产

有什么想法吗?

谢谢, Dave

更新:目前,为了实用,我添加了特定环境来对邮件程序域进行硬编码。因此,现在 demo.mydomain.comenvironments/demo.rb 上运行,而 www.mydomain.comenvironments/products 上运行.rb。我喜欢的是文件之间的重复,我不清楚如何像我一样将它们干燥,例如数据库.yml

I need some advice on configuring mail in production Ruby-on-Rails sites.

I deploy my Rails app on EngineYard. I have a couple of sites, like demo.mydomain.com or staging.mydomain.com - how can I configure Devise so that at deploy time I can make sure confirmation mails come from demo.mydomain.com or staging.mydomain.com automatically? ie, I want the same GitHub codebase, and want to fill the configuration in dynamically.

Currently in config/environments/production.rb I have the line:

config.action_mailer.default_url_options = { :host => 'demo.mydomain.com' }

But that's incorrect when the same code is deployed to staging.mydomain.com as they both run in RAILS_ENV=production

Any ideas?

Thanks,
Dave

Update: For now, to be practical, I've added specific environments to hardcode the mailer domain. So now demo.mydomain.com runs on environments/demo.rb, and www.mydomain.com runs on environments/productions.rb. What I don't like about this is the duplication between the files, it's not clear to me how to DRY them up as I have with, eg, database.yml

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮邮递员 2025-01-08 01:57:23

在您的设备配置中,通常是 config/initializers/devise.rb 您可以为设备配置邮件发送者。此配置需要一个过程,以便可以在运行时评估某些内容。

Devise.setup do |config|
  config.mailer_sender = Proc.new { your_magic_here }
end

in your devise configuration, usually config/initializers/devise.rb you can configure the mail-sender for devise. this configuration takes a proc, so that it's possible to evaluate something at runtime.

Devise.setup do |config|
  config.mailer_sender = Proc.new { your_magic_here }
end
︶葆Ⅱㄣ 2025-01-08 01:57:23

理想的舞台和表演生产服务器应该运行在不同的rails环境中。尽管如此,如果您想让生产环境同时在登台和运行环境中运行,生产服务器具有不同的操作邮件程序 URL,那么应该在部署级别完成。您始终可以在部署时编写环境文件。

Ideally staging & production servers should run on different rails environment. Still if you wanted to have production env running on both staging & production servers with different action mailer urls then it should be done at deployment level. You can always write environment file while deployment.

赠意 2025-01-08 01:57:23

首先,我认为你应该分离应用程序的环境。查看此指南了解如何做到这一点。

然后,在您的设备配置中尝试类似的操作:

Devise.setup do |config|
  if Rails.env.production?
    config.mailer_sender = "[email protected]"
  elsif Rails.env.staging?
    config.mailer_sender = "[email protected]"
  else
    config.mailer_sender = "[email protected]"
  end
  ...

检查此 指南 了解有关 Proc 对象的更多信息。

First of all, I think you should separate the environments of your application. Check this guide to learn how you can do it.

Then, try something like this in your devise configuration:

Devise.setup do |config|
  if Rails.env.production?
    config.mailer_sender = "[email protected]"
  elsif Rails.env.staging?
    config.mailer_sender = "[email protected]"
  else
    config.mailer_sender = "[email protected]"
  end
  ...

Check this guide to understand more about Proc object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文