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:
parent
3c8ddc1923
commit
16f9895048
@ -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')
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user