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
|
def show
|
||||||
# Log the view
|
# Log the view
|
||||||
@photo = Photo.find(params[:id])
|
@photo = Photo.find(params[:id])
|
||||||
@photo.views += 1
|
@photo.log_view
|
||||||
@photo.save
|
|
||||||
# Get the image and send it to the browser
|
# Get the image and send it to the browser
|
||||||
data = File.open(@photo.photo.path, 'rb').read
|
data = File.open(@photo.photo.path, 'rb').read
|
||||||
send_data(data , :filename => 'photo', :type => 'image/jpg', :disposition => 'inline')
|
send_data(data , :filename => 'photo', :type => 'image/jpg', :disposition => 'inline')
|
||||||
|
|||||||
@ -29,6 +29,15 @@ class Photo < ActiveRecord::Base
|
|||||||
self.title
|
self.title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def log_view
|
||||||
|
if self.views.nil?
|
||||||
|
self.views = 1
|
||||||
|
else
|
||||||
|
self.views += 1
|
||||||
|
end
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def get_exif
|
def get_exif
|
||||||
exif = MiniExiftool.new photo.queued_for_write[:original].path
|
exif = MiniExiftool.new photo.queued_for_write[:original].path
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user