开发者

Custom partials in exception notification in Rails 3

开发者 https://www.devze.com 2023-02-18 03:55 出处:网络
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

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 suspe开发者_Go百科ct 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.


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" <notifier@example.com>},
   :exception_recipients => %w{exceptions@example.com},
   :sections => %w{my_section1 my_section2} + ExceptionNotifier::Notifier.default_sections


From version 2.6.0 of the gem and forth, this is no longer needed. That bug is already fixed, so there's no need to have that line on an initializer anymore.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号