プロジェクトで 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 の問題なのかはわかりませんが、メールが送信されていることを考えると、エラー メッセージが表示される理由はまったくわかりません。
ご覧いただき、ご指導いただきありがとうございます。