【问题标题】:Missing template error with Exception Notification gem and Rails 3.2异常通知 gem 和 Rails 3.2 缺少模板错误
【发布时间】:2013-01-31 18:31:41
【问题描述】:

我们在项目中使用了 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-3.0.1/lib/exception_notifier/views 中寻找 /exception_notification.text.erb 视图,而不是在 exception_notifier 子目录中。在这一点上,我不确定这是否是 Rails 或 exception_notification gem 的问题,但鉴于电子邮件已发送,我不确定为什么会出现错误消息。

感谢您的浏览和任何指导。

【问题讨论】:

    标签: ruby-on-rails exception-notification


    【解决方案1】:

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

    【讨论】:

    • 这是一个有趣的方法。我没有修改我们依赖的 gem,而是将 views/exception_notifier 移动到我的 app/views 文件夹中,在我的 production.rb 文件中,我有 ExceptionNotifier::Notifier.append_view_path(File.join(Rails.root, "app", "views", "exception_notifier")) 这似乎在我的机器上工作。现在要弄清楚为什么我的 500 页面没有显示... ;)
    猜你喜欢
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 2015-04-20
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    相关资源
    最近更新 更多