2

这只是今天一个接一个的问题。我刚刚部署到我的生产服务器并对其进行了测试,每当涉及电子邮件时都会出现问题。特别是使用 Devise 的可确认注册电子邮件,每当我注册帐户时,日志中都会抛出以下错误...

ActionView::Template::Error (You can no longer call ActionMailer::Base.default_url_options directly. You need to set config.action_mailer.default_url_options. If you are using ActionMailer standalone, you need to include the routing url_helpers directly.):

查看我的 config/environments/production.rb,我有以下设置...

config.action_mailer.default_url_options = { :host => 'localhost' } 

所以 config.action_mailer.default_url_options正在使用,但被完全忽略。我尝试将主机更改为“127.0.0.1”和我的服务器的 IP 地址,但它没有。将它扔到 config/application.rb 中,但不行。我在我的项目中寻找任何其他声明 default_url_options 的行,但它只在 production.rb 文件中设置。我在 Google 上搜索并找到了一篇建议将 config.cache_classes 设置为 false 的帖子,但那里也为负数。

现在这很疯狂......每当我尝试在我的项目中提交全新的评论时,我都会遇到同样的错误(如果您是第一次评论者,请设置发送电子邮件以确认电子邮件地址)。我从 production.rb 文件中取出了 config.action_mailer...等,并且 viola - 我的评论邮件工作并发送了电子邮件就好了!

尽管如此,Devise 还是非常固执,不断向我抛出上述错误。关于为什么的任何想法?顺便说一句,我所有的宝石都是最新的。下面是我的 production.rb 文件。

---更新---------------

取得了一些进展,但这很奇怪。当我启动服务器并尝试发送邮件(用户注册、评论)时,我收到上面的 ActionMailer::Base 错误消息。当我再次尝试该操作时...它起作用并且邮件被发送。从那时起(直到乘客和/或服务器重新启动),所有邮件操作都可以正常工作。

但并非没有另一个问题(它永远不会结束)......由于某种原因,电子邮件正文完全空白。

4

3 回答 3

4

当我尝试在测试数据库中进行测试时,我最终再次遇到了这个问题,我下定决心一劳永逸地弄清楚我为什么会收到这个错误,以及为什么其他人似乎没有遇到过它(很少来自谷歌的结果)。

在完全拆除并重建我的项目后,我终于将问题定位在我安装的 Sitemap-generator 插件上。一旦我删除了所有痕迹,上述错误终于停止了。

于 2011-05-07T08:10:31.200 回答
1

我正在为 Fat Free CRM 解决这个问题,我意识到这个错误是因为 Rails 3 延迟加载类而发生的。您需要做的就是“触摸”您的环境/**.rb 文件中的 ActionMailer::Base 类,它将加载该类。然后您可以从控制器等调用 ActionMailer::Base.default_url_options (我们这样做是为了从 request.host_with_port 自动设置邮件主机)

所以我的环境文件现在看起来像这样:

FatFreeCRM::Application.configure do

  ...

  ActionMailer::Base
end
于 2011-07-19T08:12:12.983 回答
0

我相信我已经解决了这个问题......虽然我不“完全”确定它做了什么。它很可能是我注释掉的 config.cache_classes = true ,虽然我担心这会影响我的站点缓存或其他东西,但它似乎并没有破坏它。

此外,我通过从 :sendmail 切换到 :smtp 解决了空的电子邮件正文。

这是我最终的 production.rb 文件,希望这对将来有类似问题的人有用。

MyProject::Application.configure do

  # Commented out, causes 'ActionView::Template' error
  #config.cache_classes = true

  config.whiny_nils = true

  config.consider_all_requests_local = true

  config.action_view.debug_rjs = true

  config.action_controller.perform_caching = true

  config.cache_store = :mem_cache_store

  config.active_support.deprecation = :log

  config.action_dispatch.best_standards_support = :builtin

  config.action_mailer.raise_delivery_errors = true

  Sunspot.config.solr.url = 'http://127.0.0.1:8080/solr'

  Paperclip.options[:command_path] = "/usr/bin/"

  config.action_mailer.perform_deliveries = true

  config.action_mailer.delivery_method = :smtp

  ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :enable_starttls_auto => true,
    :port => 587,
    :authentication => :plain,
    :user_name => "user@domain.com",
    :password => 'password'
  }

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

  config.time_zone = "Central Time (US & Canada)"

end
于 2011-04-12T03:36:44.263 回答