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

Move views into their own controller

Thanks DHH.
This commit is contained in:
Daniel Barber 2016-03-13 18:39:09 +00:00
parent 23eb9f3e18
commit 22196755bd
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
10 changed files with 32 additions and 20 deletions

View File

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

View File

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

View File

@ -0,0 +1,10 @@
$(document).ready(function() {
return $(".fancy").fancybox({
afterLoad: function() {
$.ajax({
type: 'POST',
url: "/photos/" + (this.element.data('id')) + "/views",
});
}
});
});

View File

@ -1,4 +0,0 @@
$(document).ready ->
$(".fancy").fancybox
afterLoad: () ->
$.post "/photos/#{this.element.data('id')}/log_view"

View File

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

View File

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

View File

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

View File

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

View File

@ -11,6 +11,7 @@
<%= javascript_include_tag 'application' %>
<%= favicon_link_tag 'favicon.ico' %>
<%= render 'shared/typekit' %>
<%= csrf_meta_tags %>
</head>
<body>

View File

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