Rails 4 action_mailer主机

时间:2014-07-22 02:32:03

标签: ruby-on-rails ruby config

对于Rails 4,我在

中使用config.action_mailer.asset_host = "http://localhost:3000"

config > environments > development.rb

将资产加载到我的邮件程序。

是否有比硬编码网址更好的价值?我想应该有一个,因为我不会在我的production.rb中使用这个值。在rails config中找到当前主机url的代码是什么?

2 个答案:

答案 0 :(得分:0)

如果部署到已知主机,则可以将其直接放在production.rb

但是如果你真的需要从网址上阅读它,那么你要查看它

http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url

答案 1 :(得分:0)

如果您正在使用SendGrid,请在config/environment.rb文件中指定您的ActionMailer设置以指向SendGrid的服务器。

ActionMailer::Base.smtp_settings = {
  :user_name => 'your_sendgrid_username',
  :password => 'your_sendgrid_password',
  :domain => 'yourdomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
  }