我们在项目中使用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和文本的混合,并不完全相同&lt; screenshot&gt;并且我们日志中的错误消息是:
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的问题,但鉴于发送了电子邮件,我不确定为什么会出现错误消息。
感谢您查看并获取任何指导。
答案 0 :(得分:0)
我遇到了同样的问题,最终分配了exception_notification并改变了在notifier.rb中寻找模板的位置。 Fork位于https://github.com/etcetc/exception_notification