diff --git a/app/assets/javascripts/home.js b/app/assets/javascripts/home.js new file mode 100644 index 0000000..09b2da0 --- /dev/null +++ b/app/assets/javascripts/home.js @@ -0,0 +1,3 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. +// You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/home.js.coffee b/app/assets/javascripts/home.js.coffee deleted file mode 100644 index 7615679..0000000 --- a/app/assets/javascripts/home.js.coffee +++ /dev/null @@ -1,3 +0,0 @@ -# Place all the behaviors and hooks related to the matching controller here. -# All this logic will automatically be available in application.js. -# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/javascripts/photos.js b/app/assets/javascripts/photos.js new file mode 100644 index 0000000..d8944b3 --- /dev/null +++ b/app/assets/javascripts/photos.js @@ -0,0 +1,10 @@ +$(document).ready(function() { + return $(".fancy").fancybox({ + afterLoad: function() { + $.ajax({ + type: 'POST', + url: "/photos/" + (this.element.data('id')) + "/views", + }); + } + }); +}); diff --git a/app/assets/javascripts/photos.js.coffee b/app/assets/javascripts/photos.js.coffee deleted file mode 100644 index 9a7f52e..0000000 --- a/app/assets/javascripts/photos.js.coffee +++ /dev/null @@ -1,4 +0,0 @@ -$(document).ready -> - $(".fancy").fancybox - afterLoad: () -> - $.post "/photos/#{this.element.data('id')}/log_view" diff --git a/app/assets/javascripts/views.js b/app/assets/javascripts/views.js new file mode 100644 index 0000000..4532725 --- /dev/null +++ b/app/assets/javascripts/views.js @@ -0,0 +1,3 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. +// You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/views.sass b/app/assets/stylesheets/views.sass new file mode 100644 index 0000000..7be4dcc --- /dev/null +++ b/app/assets/stylesheets/views.sass @@ -0,0 +1,3 @@ +// Place all the styles related to the views controller here. +// They will automatically be included in application.css. +// You can use Sass here: http://sass-lang.com/ diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index f4c2609..19f5642 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -13,16 +13,6 @@ class PhotosController < ApplicationController end end - def log_view - photo = Photo.find_by_id(params[:id]) - if photo.present? - photo.log_view - head :ok - else - head :not_found - end - end - private def for_category(category_id) diff --git a/app/controllers/views_controller.rb b/app/controllers/views_controller.rb new file mode 100644 index 0000000..543532d --- /dev/null +++ b/app/controllers/views_controller.rb @@ -0,0 +1,11 @@ +class ViewsController < ApplicationController + def create + photo = Photo.find_by_id(params[:photo_id]) + if photo.present? + photo.log_view + head :ok + else + head :not_found + end + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 037ea95..2b6daa7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,6 +11,7 @@ <%= javascript_include_tag 'application' %> <%= favicon_link_tag 'favicon.ico' %> <%= render 'shared/typekit' %> + <%= csrf_meta_tags %> diff --git a/config/routes.rb b/config/routes.rb index 77885d7..a1309a5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,9 +27,7 @@ DanBarberPhoto::Application.routes.draw do end resources :photos do - member do - post :log_view - end + resources :views, only: [:create] end resources :contacts, only: [:new, :create]