3

我们在项目中使用 exception_notification gem,现在我们看到缺少模板错误。这是我们的设置的样子:

# Gemfile
gem 'exception_notification'

# config/initializers/exception_notifications.rb
if Rails.env.production?  
    server_hostname = `hostname`.chomp
    Rails.application.config.middleware.use ExceptionNotifier, 
    :exception_recipients => %w(webdev@domain.com),
    :sender_address =>  %("Application Error" <admin@domain.com>),
    :email_prefix => "[#{server_hostname}] "
end

当异常发生时,我们确实收到了电子邮件,但呈现的错误页面是原始 ERB 和文本的无样式混合,一点也不漂亮 < screenshot > 我们日志中的错误消息是:

ActionView::MissingTemplate (Missing template /exception_notification with {:locale=>[:en], :formats=>[:text], :handlers=>[:erb, :builder]}. Searched in:
    * "/Users/j/Projects/agilebits/app/views"
    * "/Users/j/Projects/agilebits/vendor/bundle/ruby/1.9.1/gems/exception_notification-3.0.1/lib/exception_notifier/views"
):

当然,视图不在我的app/views文件夹中,但在我的 gems 文件夹中:

↪ ls -R /Users/j/Projects/agilebits/vendor/bundle/ruby/1.9.1/gems/exception_notification-3.0.1/lib/exception_notifier/views
exception_notifier

/Users/j/Projects/agilebits/vendor/bundle/ruby/1.9.1/gems/exception_notification-3.0.1/lib/exception_notifier/views/exception_notifier:
_backtrace.html.erb                        _request.html.erb                          background_exception_notification.html.erb
_backtrace.text.erb                        _request.text.erb                          background_exception_notification.text.erb
_data.html.erb                             _session.html.erb                          exception_notification.html.erb
_data.text.erb                             _session.text.erb                          exception_notification.text.erb
_environment.html.erb                      _title.html.erb
_environment.text.erb                      _title.text.erb

看起来 Rails 正在寻找视图 /exception_notification.text.erb ,exception_notification-3.0.1/lib/exception_notifier/views而不是在那里的exception_notifier子目录中。在这一点上,我不确定这是否是 Rails 或 exception_notification gem 的问题,但鉴于电子邮件已发送,我不确定为什么会出现错误消息。

感谢您查看并提供任何指导。

4

1 回答 1

0

我遇到了同样的问题,最终分叉了 exception_notification 并更改了它在 notifier.rb 中查找模板的位置。Fork 在https://github.com/etcetc/exception_notification

于 2013-02-15T18:07:02.380 回答