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

Updated photos model to use named scopes. Cleaned up some code. Added

meta_where as a gem, although I'm not using it yet.
This commit is contained in:
Dan Barber 2010-12-14 12:51:34 -05:00
parent 60f00e33be
commit 85cf2fb4b8
8 changed files with 19 additions and 10 deletions

View File

@ -31,6 +31,7 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier' gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'
gem 'pg' gem 'pg'
gem 'meta_where'
gem 'typus', :git => 'git://github.com/fesplugas/typus.git' 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'

View File

@ -57,6 +57,10 @@ GEM
activesupport (>= 2.3.6) activesupport (>= 2.3.6)
mime-types mime-types
treetop (>= 1.4.5) treetop (>= 1.4.5)
meta_where (0.9.6)
activerecord (~> 3.0.0)
activesupport (~> 3.0.0)
arel (~> 1.0.1)
mime-types (1.16) mime-types (1.16)
mini_exiftool (1.0.1) mini_exiftool (1.0.1)
pg (0.9.0) pg (0.9.0)
@ -92,6 +96,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
exception_notification! exception_notification!
meta_where
mini_exiftool mini_exiftool
pg pg
rails (= 3.0.0) rails (= 3.0.0)

View File

@ -5,9 +5,7 @@ class CategoriesController < ApplicationController
def index def index
@categories = Category.order('sort ASC').paginate :all, :page => params[:page], :per_page => 4 @categories = Category.order('sort ASC').paginate :all, :page => params[:page], :per_page => 4
@num_categories = @categories.count @photos = Photo.featured.limit(2).order('RANDOM()')
@photos = Photo.where(:enabled => true).where(:featured => true).limit(2).order('RANDOM()')
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb

View File

@ -2,7 +2,7 @@ class PagesController < ApplicationController
layout "photos" layout "photos"
def index def index
@photo = Photo.where(:featured => true).where(:enabled => true).order('RANDOM()').first @photo = Photo.featured.order('RANDOM()').first
end end
def about def about

View File

@ -7,11 +7,9 @@ class PhotosController < ApplicationController
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.where(:enabled => true).paginate(:page => params[:page], :per_page => 11) @photos = @category.photos.enabled.paginate(:page => params[:page], :per_page => 11)
@num_photos = @photos.count
else else
@photos = Photo.paginate :all, :page => params[:page], :per_page => 11 @photos = Photo.enabled.paginate :all, :page => params[:page], :per_page => 11
@num_photos = @photos.count
end end
respond_to do |format| respond_to do |format|
format.html format.html

View File

@ -13,6 +13,13 @@ class Photo < ActiveRecord::Base
after_create :get_exif after_create :get_exif
@@per_page = 11 @@per_page = 11
scope :enabled, lambda {
where(:enabled => true)
}
scope :featured, lambda {
enabled.where(:featured => true)
}
def to_s def to_s
self.title self.title

View File

@ -10,7 +10,7 @@
</div> </div>
</div> </div>
<% @num_blank = 4 - @num_categories -%> <% @num_blank = 4 - @categories.count -%>
<div class="sg-24 sgParent"> <div class="sg-24 sgParent">

View File

@ -22,7 +22,7 @@
</div> </div>
<% end %> <% end %>
<% @num_blank = 11 - @num_photos -%> <% @num_blank = 11 - @photos.count -%>
<% @photos.each do |photo| %> <% @photos.each do |photo| %>