铁轨和设计:如何自动配置域名邮件?
我需要一些有关在生产 Ruby-on-Rails 站点中配置邮件的建议。
我在 EngineYard 上部署 Rails 应用程序。我有几个网站,例如 demo.mydomain.com
或 staging.mydomain.com
- 如何配置 Devise,以便在部署时我可以确保收到确认邮件自动来自 demo.mydomain.com
或 staging.mydomain.com
? ie,我想要相同的 GitHub 代码库,并且想要动态填充配置。
目前在 config/environments/production.rb 中,我有以下行:
config.action_mailer.default_url_options = { :host => 'demo.mydomain.com' }
但是,当将相同的代码部署到 staging.mydomain.com 时,这是不正确的,因为它们都在 RAILS_ENV=生产
有什么想法吗?
谢谢, Dave
更新:目前,为了实用,我添加了特定环境来对邮件程序域进行硬编码。因此,现在 demo.mydomain.com
在 environments/demo.rb
上运行,而 www.mydomain.com
在 environments/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的设备配置中,通常是
config/initializers/devise.rb
您可以为设备配置邮件发送者。此配置需要一个过程,以便可以在运行时评估某些内容。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.理想的舞台和表演生产服务器应该运行在不同的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.
首先,我认为你应该分离应用程序的环境。查看此指南了解如何做到这一点。
然后,在您的设备配置中尝试类似的操作:
检查此 指南 了解有关 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:
Check this guide to understand more about Proc object.