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:
parent
57418726ca
commit
3c8ddc1923
1
Gemfile
1
Gemfile
@ -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'
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -1,22 +1,28 @@
|
|||||||
class PhotosController < ApplicationController
|
class PhotosController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@photo = Photo.new
|
@photo = Photo.new
|
||||||
@categories = Category.find(:all).map { |c| [c.name, c.id] }
|
@categories = Category.find(:all).map { |c| [c.name, c.id] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
if params[:category_id]
|
if params[:category_id]
|
||||||
@category = Category.find_by_id(params[:category_id])
|
@category = Category.find_by_id(params[:category_id])
|
||||||
@photos = @category.photos.enabled.order(:taken_at.desc).paginate(:page => params[:page], :per_page => 11)
|
@photos = @category.photos.enabled.order(:taken_at.desc).paginate(:page => params[:page], :per_page => 11)
|
||||||
else
|
else
|
||||||
@photos = Photo.enabled.order(:taken_at.desc).paginate :all, :page => params[:page], :per_page => 11
|
@photos = Photo.enabled.order(:taken_at.desc).paginate :all, :page => params[:page], :per_page => 11
|
||||||
end
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@photo = Photo.find(params[:id])
|
# Log the view
|
||||||
end
|
@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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
<% @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 %>
|
||||||
|
|||||||
@ -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>
|
||||||
|
|
||||||
@ -26,4 +26,4 @@
|
|||||||
<%= link_to raw('<span>contact</span>'), new_contact_url %>
|
<%= link_to raw('<span>contact</span>'), new_contact_url %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -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 %>
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
<% @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 %>
|
||||||
|
|||||||
9
db/migrate/20101216180143_add_view_count_to_photos.rb
Normal file
9
db/migrate/20101216180143_add_view_count_to_photos.rb
Normal 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
|
||||||
@ -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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user