From: Herve Saint-Amand Date: Sun, 1 Jan 2017 22:11:56 +0000 (+0000) Subject: Better loading of attached images X-Git-Tag: live~3632^2~35 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/b5ef2be021d84d8e05575d1569bacd3446d148db?ds=inline Better loading of attached images Got rid of that big ugly base64 blob which was only a temporary crutch anyway. Added a png file instead. Use File.read rather than File.open for a 66% reduction in verbosity. --- diff --git a/app/assets/images/osm_logo_30.png b/app/assets/images/osm_logo_30.png new file mode 100644 index 000000000..c963f4f4a Binary files /dev/null and b/app/assets/images/osm_logo_30.png differ diff --git a/app/models/notifier.rb b/app/models/notifier.rb index ea10eeb7b..bfcdc499e 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -173,15 +173,8 @@ class Notifier < ActionMailer::Base I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter) end - attachments.inline['osm_logo_30x30.png'] = { - mime_type: 'image/png', - encoding: 'base64', - content: @@osm_logo_png_bytes, - } - - File.open(user_avatar_file_path(comment.author), 'rb') do |file| - attachments.inline['avatar.png'] = file.read() - end + attachments.inline['logo.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'osm_logo_30.png')) + attachments.inline['avatar.png'] = File.read(user_avatar_file_path(comment.author)) mail :to => recipient.email, :subject => subject end @@ -216,59 +209,4 @@ class Notifier < ActionMailer::Base end end - # FIXME - 2016-12-28 - saintamh - someone please show me a better way to - # include this blob in here. If I save it under app/assets, how do I get a - # path to it in a portable way? - @@osm_logo_png_bytes = < - <%= image_tag attachments["osm_logo_30x30.png"].url, alt: "OpenStreetMap logo", title: "OpenStreetMap", height: "30", width: "30", border: "0" %> + <%= image_tag attachments["logo.png"].url, alt: "OpenStreetMap logo", title: "OpenStreetMap", height: "30", width: "30", border: "0" %>