【发布时间】: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