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

Added view count to photos. Used acts_as_markdown for pages.

This commit is contained in:
Dan Barber 2010-12-18 08:31:12 -05:00
parent 57418726ca
commit 3c8ddc1923
11 changed files with 54 additions and 30 deletions

View File

@ -36,3 +36,4 @@ gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
gem 'mini_exiftool' gem 'mini_exiftool'
gem 'will_paginate', :git => 'http://github.com/mislav/will_paginate.git', :branch => 'rails3' gem 'will_paginate', :git => 'http://github.com/mislav/will_paginate.git', :branch => 'rails3'
gem 'rdiscount' gem 'rdiscount'
gem 'acts_as_markup'

View File

@ -20,6 +20,7 @@ GIT
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
RedCloth (4.2.3)
abstract (1.0.0) abstract (1.0.0)
actionmailer (3.0.0) actionmailer (3.0.0)
actionpack (= 3.0.0) actionpack (= 3.0.0)
@ -47,6 +48,12 @@ GEM
activemodel (= 3.0.0) activemodel (= 3.0.0)
activesupport (= 3.0.0) activesupport (= 3.0.0)
activesupport (3.0.0) activesupport (3.0.0)
acts_as_markup (1.3.4)
RedCloth (~> 4.2)
activerecord (>= 2.3.2)
activesupport (>= 2.3.2)
rdiscount (~> 1.3)
wikitext (~> 2.0)
arel (1.0.1) arel (1.0.1)
activesupport (~> 3.0.0) activesupport (~> 3.0.0)
builder (2.1.2) builder (2.1.2)
@ -90,11 +97,13 @@ GEM
treetop (1.4.8) treetop (1.4.8)
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.23) tzinfo (0.3.23)
wikitext (2.1.1)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
acts_as_markup
exception_notification! exception_notification!
meta_where meta_where
mini_exiftool mini_exiftool

View File

@ -6,6 +6,7 @@ class PagesController < ApplicationController
end end
def about def about
@content = Page.find_by_name('about') @page = Page.find_by_name('about')
@content = @page.content
end end
end end

View File

@ -17,6 +17,12 @@ class PhotosController < ApplicationController
end end
def show def show
# Log the view
@photo = Photo.find(params[:id]) @photo = Photo.find(params[:id])
@photo.views += 1
@photo.save
# Get the image and send it to the browser
data = File.open(@photo.photo.path, 'rb').read
send_data(data , :filename => 'photo', :type => 'image/jpg', :disposition => 'inline')
end end
end end

View File

@ -1,8 +1,5 @@
require 'rdiscount' require 'rdiscount'
class Page < ActiveRecord::Base class Page < ActiveRecord::Base
def html acts_as_markdown :content
markdown = Markdown.new(self.content, :smart)
markdown.to_html
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, :rel => 'photo', :class => 'fancy' %> <%= link_to '', photo_url(photo, :format => :jpg), :class => 'fancy' %>
</div> </div>
<% end %> <% end %>

View File

@ -9,7 +9,7 @@
<div class="sg-11 about-content"> <div class="sg-11 about-content">
<div> <div>
<%= raw(@content.html) %> <%= raw(@content.to_html) %>
</div> </div>
</div> </div>

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, :rel => 'photo', :class => 'fancy' %> <%= link_to '', photo_url(@photo, :format => :jpg), :rel => 'photo', :class => 'fancy' %>
</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, :rel => 'photo', :class => 'fancy' %> <%= link_to '', photo_url(photo, :format => :jpg), :class => 'fancy' %>
</div> </div>
<% end %> <% end %>

View File

@ -0,0 +1,9 @@
class AddViewCountToPhotos < ActiveRecord::Migration
def self.up
add_column :photos, :views, :integer, :default => 0
end
def self.down
remove_column :photos, :views
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20101215172105) do ActiveRecord::Schema.define(:version => 20101216180143) do
create_table "admin_users", :force => true do |t| create_table "admin_users", :force => true do |t|
t.string "first_name", :default => "", :null => false t.string "first_name", :default => "", :null => false
@ -63,6 +63,7 @@ ActiveRecord::Schema.define(:version => 20101215172105) do
t.boolean "featured", :default => false t.boolean "featured", :default => false
t.boolean "enabled", :default => true t.boolean "enabled", :default => true
t.datetime "taken_at" t.datetime "taken_at"
t.integer "views", :default => 0
end end
end end