From fb0fcdb1206b596699f5dfe461d6cb359fd4ccf0 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Thu, 15 Oct 2015 17:41:42 +0100 Subject: [PATCH] Restore fetching of attributes from EXIF --- app/models/photo.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index ce0b17e..88dcb2b 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -8,9 +8,10 @@ class Photo < ActiveRecord::Base self.per_page = 11 scope :enabled, -> { where(enabled: true) } - scope :featured, -> { enabled.where(featured: true) } + after_create :process_exif + def to_s title end @@ -27,4 +28,17 @@ class Photo < ActiveRecord::Base end save end + + private + + def process_exif + self.title = exif.title if title.empty? + self.description = exif.description if description.empty? + self.taken_at = exif.date_time_original + save + end + + def exif + @exif ||= MiniExiftool.new(image.file.path) + end end