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:
parent
60f00e33be
commit
85cf2fb4b8
1
Gemfile
1
Gemfile
@ -31,6 +31,7 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
|
||||
|
||||
gem "exception_notification", :git => "git://github.com/rails/exception_notification", :require => 'exception_notifier'
|
||||
gem 'pg'
|
||||
gem 'meta_where'
|
||||
gem 'typus', :git => 'git://github.com/fesplugas/typus.git'
|
||||
gem 'mini_exiftool'
|
||||
gem 'will_paginate', :git => 'http://github.com/mislav/will_paginate.git', :branch => 'rails3'
|
||||
|
||||
@ -57,6 +57,10 @@ GEM
|
||||
activesupport (>= 2.3.6)
|
||||
mime-types
|
||||
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)
|
||||
mini_exiftool (1.0.1)
|
||||
pg (0.9.0)
|
||||
@ -92,6 +96,7 @@ PLATFORMS
|
||||
|
||||
DEPENDENCIES
|
||||
exception_notification!
|
||||
meta_where
|
||||
mini_exiftool
|
||||
pg
|
||||
rails (= 3.0.0)
|
||||
|
||||
@ -5,9 +5,7 @@ class CategoriesController < ApplicationController
|
||||
def index
|
||||
@categories = Category.order('sort ASC').paginate :all, :page => params[:page], :per_page => 4
|
||||
|
||||
@num_categories = @categories.count
|
||||
|
||||
@photos = Photo.where(:enabled => true).where(:featured => true).limit(2).order('RANDOM()')
|
||||
@photos = Photo.featured.limit(2).order('RANDOM()')
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
||||
@ -2,7 +2,7 @@ class PagesController < ApplicationController
|
||||
layout "photos"
|
||||
|
||||
def index
|
||||
@photo = Photo.where(:featured => true).where(:enabled => true).order('RANDOM()').first
|
||||
@photo = Photo.featured.order('RANDOM()').first
|
||||
end
|
||||
|
||||
def about
|
||||
|
||||
@ -7,11 +7,9 @@ class PhotosController < ApplicationController
|
||||
def index
|
||||
if params[:category_id]
|
||||
@category = Category.find_by_id(params[:category_id])
|
||||
@photos = @category.photos.where(:enabled => true).paginate(:page => params[:page], :per_page => 11)
|
||||
@num_photos = @photos.count
|
||||
@photos = @category.photos.enabled.paginate(:page => params[:page], :per_page => 11)
|
||||
else
|
||||
@photos = Photo.paginate :all, :page => params[:page], :per_page => 11
|
||||
@num_photos = @photos.count
|
||||
@photos = Photo.enabled.paginate :all, :page => params[:page], :per_page => 11
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
||||
@ -13,6 +13,13 @@ class Photo < ActiveRecord::Base
|
||||
after_create :get_exif
|
||||
|
||||
@@per_page = 11
|
||||
|
||||
scope :enabled, lambda {
|
||||
where(:enabled => true)
|
||||
}
|
||||
scope :featured, lambda {
|
||||
enabled.where(:featured => true)
|
||||
}
|
||||
|
||||
def to_s
|
||||
self.title
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% @num_blank = 4 - @num_categories -%>
|
||||
<% @num_blank = 4 - @categories.count -%>
|
||||
|
||||
<div class="sg-24 sgParent">
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% @num_blank = 11 - @num_photos -%>
|
||||
<% @num_blank = 11 - @photos.count -%>
|
||||
|
||||
<% @photos.each do |photo| %>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user