Commit 246b113be1c68041792bf3558fc8cccd7feb8c41

Authored by Nathan Broadbent
1 parent a437bba8
Exists in master and in 1 other branch production

Added html email template for err_notification. Also made it send a shortened ba…

…cktrace that only contains files from the project. More work to be done: create an actionmailer layout, add the deployments template, and update the text templates to match the new html content.
app/mailers/mailer.rb
  1 +# Haml doesn't load routes automatically when called via a rake task.
  2 +# This is only necessary when sending test emails (i.e. from rake hoptoad:test)
  3 +require Rails.root.join('config/routes.rb')
  4 +
1 5 class Mailer < ActionMailer::Base
2 6 default :from => Errbit::Config.email_from
3 7  
... ...
app/models/notice.rb
... ... @@ -85,6 +85,11 @@ class Notice
85 85 err.update_attributes(:last_notice_at => created_at)
86 86 end
87 87  
  88 + # Backtrace containing only files from the app itself (ignore gems)
  89 + def app_backtrace
  90 + backtrace.select { |l| l && l['file'] && l['file'].include?("[PROJECT_ROOT]") }
  91 + end
  92 +
88 93 protected
89 94  
90 95 def should_notify?
... ...
app/views/mailer/_signature.html.haml 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +%table(cellpadding="0" cellspacing="0" border="0" align="left" width="100%")
  2 + %tbody
  3 + %tr
  4 + %td(style="padding:10px 20px 20px 20px; font-size:11px; font-family:Helvetica,Arial,sans-serif; font-weight:bold; color:#666666; text-align:left; border-top:1px solid #dddddd;")
  5 + Your loyal servant,
  6 + = link_to 'Errbit', root_path
  7 +
... ...
app/views/mailer/err_notification.html.haml 0 → 100644
... ... @@ -0,0 +1,54 @@
  1 +%html
  2 + %head
  3 + %body
  4 + %div
  5 + %table(cellpadding="0" cellspacing="0" border="0" width="100%")
  6 + %tbody
  7 + %tr
  8 + %td(style="padding:10px 20px 10px 20px; height: 75px; background-color: #11112f; text-align:left; border-bottom:1px solid #ccccee;")
  9 + = link_to image_tag(URI.join(root_url,"stylesheets/images/logo.png").to_s), root_url, :style => "display: block; height: 31px; width: 88px; margin-top: 10px;"
  10 + %tr
  11 + %td(style="padding:0px 0px 10px 0px; font-family:Helvetica,Arial,sans-serif; font-size:14px; background-color:#ffffff; text-align:left; border-bottom:1px solid #dddddd;")
  12 + %table(cellpadding="0" cellspacing="0" border="0" align="left")
  13 + %tbody
  14 + %tr
  15 + %td(valign="top" style="padding:0px 20px 10px 20px; font-family:Helvetica,Arial,sans-serif; font-size:14px; background-color:#ffffff; text-align:left;")
  16 + %div(style="line-height:1.3em;")
  17 + %p(style="margin-top: 22px; margin-bottom:2px")
  18 + An err has just occurred in
  19 + = link_to(@app.name, app_url(@app), :style => "color:#000; font-weight: bold;") << ","
  20 + on the
  21 + %span(style="color:#000; font-weight: bold;")= @notice.err.environment
  22 + environment.
  23 + %p(style="margin-top: 0; margin-bottom:2px")
  24 + This err has occurred #{pluralize @notice.err.notices_count, 'time'}.
  25 + %p(style="padding:10px 0 5px 0; margin: 0;")
  26 + = link_to("Click here to view the error on Errbit", app_err_url(@app, @notice.err), :style => "font-weight:bold;") << "."
  27 + %tr
  28 + %td(style="padding-top:0; padding-bottom:10px; text-align:left;")
  29 + %table(cellpadding="0" cellspacing="0" border="0" align="left")
  30 + %tbody
  31 + %tr
  32 + %td(valign="top" style="padding:10px 20px 10px 20px; font-family:Helvetica,Arial,sans-serif; font-size:14px; background-color:#ffffff; text-align:left;")
  33 + %div(style="line-height:1.3em;")
  34 + %p(style="color:#777777; margin-top: 10px; margin-bottom: 2px;")
  35 + Error Message:
  36 + %p(style="margin-top:0;")
  37 + = raw(@notice.err.message)
  38 + %p(style="color:#777777; padding:10px 0 0 0; margin-bottom:0px;")
  39 + Where:
  40 + %p(style="margin-top:0; font-family:monospace")
  41 + = @notice.err.where
  42 + %p(style="color:#777777; padding:10px 0 0 0; margin-bottom:0px;")
  43 + URL:
  44 + %p(style="margin-top:0; margin-bottom:0; font-family:monospace;")
  45 + - if @notice.request['url'].present?
  46 + = link_to @notice.request['url'], @notice.request['url']
  47 + %p(style="color:#777777; padding:10px 0 0 0; margin-bottom:0px;")
  48 + App Backtrace:
  49 + - @notice.app_backtrace.map{|l| "#{l['file']}:#{l['number']}" }.each do |backtrace_line|
  50 + %p(style="margin-top:0; margin-bottom:0; font-family:monospace")= backtrace_line
  51 +
  52 + = render :partial => 'signature'
  53 + %br
  54 +
... ...