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:
parent
23eb9f3e18
commit
22196755bd
3
app/assets/javascripts/home.js
Normal file
3
app/assets/javascripts/home.js
Normal 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/
|
||||||
@ -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/
|
|
||||||
10
app/assets/javascripts/photos.js
Normal file
10
app/assets/javascripts/photos.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
$(document).ready(function() {
|
||||||
|
return $(".fancy").fancybox({
|
||||||
|
afterLoad: function() {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: "/photos/" + (this.element.data('id')) + "/views",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,4 +0,0 @@
|
|||||||
$(document).ready ->
|
|
||||||
$(".fancy").fancybox
|
|
||||||
afterLoad: () ->
|
|
||||||
$.post "/photos/#{this.element.data('id')}/log_view"
|
|
||||||
3
app/assets/javascripts/views.js
Normal file
3
app/assets/javascripts/views.js
Normal 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/
|
||||||
3
app/assets/stylesheets/views.sass
Normal file
3
app/assets/stylesheets/views.sass
Normal 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/
|
||||||
@ -13,16 +13,6 @@ class PhotosController < ApplicationController
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def for_category(category_id)
|
def for_category(category_id)
|
||||||
|
|||||||
11
app/controllers/views_controller.rb
Normal file
11
app/controllers/views_controller.rb
Normal 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
|
||||||
@ -11,6 +11,7 @@
|
|||||||
<%= javascript_include_tag 'application' %>
|
<%= javascript_include_tag 'application' %>
|
||||||
<%= favicon_link_tag 'favicon.ico' %>
|
<%= favicon_link_tag 'favicon.ico' %>
|
||||||
<%= render 'shared/typekit' %>
|
<%= render 'shared/typekit' %>
|
||||||
|
<%= csrf_meta_tags %>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@ -27,9 +27,7 @@ DanBarberPhoto::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :photos do
|
resources :photos do
|
||||||
member do
|
resources :views, only: [:create]
|
||||||
post :log_view
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :contacts, only: [:new, :create]
|
resources :contacts, only: [:new, :create]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user