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 とテキストのスタイル設定されていない混合物であり、まったく見栄えがよくありません <スクリーンショット> であり、ログのエラー メッセージは次のとおりです。

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

私は同じ問題を抱えていて、例外_通知をフォークし、notifier.rb でテンプレートを探す場所を変更しました。フォークはhttps://github.com/etcetc/exception_notificationにあります

于 2013-02-15T18:07:02.380 に答える