1
0
mirror of https://github.com/danbee/danbarberphoto synced 2025-03-04 08:49:07 +00:00

Fixed problem where views could be null. Moved view increment to model.

This commit is contained in:
Dan Barber 2010-12-18 08:55:17 -05:00
parent 3c8ddc1923
commit 16f9895048
2 changed files with 10 additions and 2 deletions

View File

@ -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')

View File

@ -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