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