diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index c9a0d57..e700f6e 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -19,8 +19,7 @@ class PhotosController < ApplicationController def show # Log the view @photo = Photo.find(params[:id]) - @photo.views += 1 - @photo.save + @photo.log_view # Get the image and send it to the browser data = File.open(@photo.photo.path, 'rb').read send_data(data , :filename => 'photo', :type => 'image/jpg', :disposition => 'inline') diff --git a/app/models/photo.rb b/app/models/photo.rb index e0131e2..0844b25 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -29,6 +29,15 @@ class Photo < ActiveRecord::Base self.title end + def log_view + if self.views.nil? + self.views = 1 + else + self.views += 1 + end + self.save + end + private def get_exif exif = MiniExiftool.new photo.queued_for_write[:original].path