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

Now reliably logging photo views with an onComplete function on the

fancybox plugin.
This commit is contained in:
Dan Barber 2010-12-18 11:17:05 -05:00
parent 54ea0d9c33
commit 67e7f0eb12
7 changed files with 19 additions and 5 deletions

View File

@ -19,5 +19,6 @@ class PhotosController < ApplicationController
def log_view def log_view
@photo = Photo.find(params[:id]) @photo = Photo.find(params[:id])
@photo.log_view @photo.log_view
render :nothing => true
end end
end end

View File

@ -1,2 +1,5 @@
module PhotosHelper module PhotosHelper
def link_to_photo(photo)
link_to '', photo.photo.url, :rel => 'photos', :class => 'fancy', :id => photo.id
end
end end

View File

@ -17,7 +17,7 @@
<% @photos.each do |photo| %> <% @photos.each do |photo| %>
<div class="sg-11 photo" style="background: url('<%= photo.photo.url(:size11) %>')"> <div class="sg-11 photo" style="background: url('<%= photo.photo.url(:size11) %>')">
<%= link_to '', photo.photo.url, :class => 'fancy' %> <%= link_to_photo photo %>
</div> </div>
<% end %> <% end %>

View File

@ -8,7 +8,7 @@
<% if @photo %> <% if @photo %>
<div class="sg-17 photo" style="background: url('<%= @photo.photo.url(:size17) %>')"> <div class="sg-17 photo" style="background: url('<%= @photo.photo.url(:size17) %>')">
<%= link_to '', @photo.photo.url, :class => 'fancy' %> <%= link_to_photo @photo %>
</div> </div>
<% end %> <% end %>

View File

@ -27,7 +27,7 @@
<% @photos.each do |photo| %> <% @photos.each do |photo| %>
<div class="sg-5 photo" style="background: url('<%= photo.photo.url(:size5) %>')"> <div class="sg-5 photo" style="background: url('<%= photo.photo.url(:size5) %>')">
<%= link_to '', photo.photo.url, :class => 'fancy' %> <%= link_to_photo photo %>
</div> </div>
<% end %> <% end %>

View File

@ -56,9 +56,16 @@ Photos::Application.routes.draw do
resources :categories do resources :categories do
resources :photos resources :photos
member do
get :log_view
end
end end
resources :photos resources :photos do
member do
get :log_view
end
end
root :to => 'pages#index' root :to => 'pages#index'

View File

@ -1,6 +1,9 @@
$(document).ready(function() { $(document).ready(function() {
$('.fancy').fancybox({ $('.fancy').fancybox({
'titlePosition' : 'inside' 'titlePosition' : 'inside',
'onComplete' : function(links, index) {
$.get('/photos/'+$(links[index]).attr('id')+'/log_view')
}
}); });
if ($('#contact_form').length) { if ($('#contact_form').length) {