Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom partials in exception notification in Rails 3

I am trying to set up a custom partial for my exception notification mails in a Rails 3 app using the current version (2.4.0) of the exception_notification gem

The README clearly states that "you can customize how each of those sections are rendered by placing a partial named for that part in your app/views/exception_notifier directory [...] You can even add new sections that describe application-specific data"

And I am exactly trying these: Altering existing sections and adding a new custom section. When just altering a section, my changed partial (app/views/exception_notifier/_session.text.erb) has no effect. When I add a new custom section, I get the following error in the log:

ActionView::Template::Error (Missing partial exception_notifier/user with {:formats=>
[:text], :handlers=>[:haml, :rjs, :rhtml, :builder, :erb, :rxml], :locale=>[:de]} in
view paths "/usr/lib/ruby/gems/1.8/gems/exception_notification-2.4.0/lib/exception_notifier/views"):

What am I doing wrong? I suspect that the view path is somehow messed up and that the exception_notifier doesn't bother to look in my /app/views/exception_notifier directory at all.

like image 232
tbk Avatar asked Dec 22 '22 16:12

tbk


1 Answers

When exception_notification is used as a gem, the only view_path configured for the notifier is the gem own view path. In order to override default section template or add you your own you will have to add your application template folder in the view path

Just add to your initializer

 ExceptionNotifier::Notifier.prepend_view_path File.join(Rails.root, 'app/views')

If you have your own section partial don't forget to add it in the middleware options

 Whatever::Application.config.middleware.use ExceptionNotifier,
   :email_prefix => "[Whatever] ",
   :sender_address => %{"notifier" <[email protected]>},
   :exception_recipients => %w{[email protected]},
   :sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_sections
like image 87
Nel Avatar answered Dec 24 '22 04:12

Nel