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

Everything is working well, categories and photos are a 1 to many right now though and they need to be many to many.

This commit is contained in:
Dan Barber 2010-10-08 13:15:18 -04:00
parent 0c61aaf604
commit b35354a764
40 changed files with 4396 additions and 9 deletions

Binary file not shown.

View File

@ -0,0 +1,84 @@
class CategoriesController < ApplicationController
layout "photos"
# GET /categories
# GET /categories.xml
def index
@categories = Category.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @categories }
end
end
# GET /categories/1
# GET /categories/1.xml
def show
@category = Category.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @category }
end
end
# GET /categories/new
# GET /categories/new.xml
def new
@category = Category.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @category }
end
end
# GET /categories/1/edit
def edit
@category = Category.find(params[:id])
end
# POST /categories
# POST /categories.xml
def create
@category = Category.new(params[:category])
respond_to do |format|
if @category.save
format.html { redirect_to(@category, :notice => 'Category was successfully created.') }
format.xml { render :xml => @category, :status => :created, :location => @category }
else
format.html { render :action => "new" }
format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
end
end
end
# PUT /categories/1
# PUT /categories/1.xml
def update
@category = Category.find(params[:id])
respond_to do |format|
if @category.update_attributes(params[:category])
format.html { redirect_to(@category, :notice => 'Category was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /categories/1
# DELETE /categories/1.xml
def destroy
@category = Category.find(params[:id])
@category.destroy
respond_to do |format|
format.html { redirect_to(categories_url) }
format.xml { head :ok }
end
end
end

View File

@ -1,11 +1,17 @@
class PhotosController < ApplicationController
def new
@photo = Photo.new
@categories = Category.find(:all).map { |c| [c.name, c.id] }
end
def index
if params[:category_id]
@category = Category.find_by_id(params[:category_id])
@photos = Photo.find(:all, :conditions => { :category_id => params[:category_id] })
else
@photos = Photo.find(:all)
end
end
def create
@photo = Photo.new(params[:photo])

View File

@ -0,0 +1,2 @@
module CategoriesHelper
end

Binary file not shown.

View File

@ -1,5 +1,22 @@
require 'exifr'
class Photo < ActiveRecord::Base
belongs_to :category
has_attached_file :photo, :styles => { :large => "1024x1024>", :thumb => "140x140#", :admin_thumb => "40x40#" }
has_attached_file :photo, :styles => { :original => "1024x1024>",
:size11 => "308x308#",
:size8 => "224x224#",
:size5 => "140x140#",
:size3 => "84x84#",
:size2 => "56x56#" }
validates_presence_of :category
before_post_process :get_exif
private
def get_exif
exif = EXIFR::JPEG.new(photo.queued_for_write[:original].path)
self.description = exif.image_description
end
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,28 @@
<h1>Editing category</h1>
<% form_for(@category) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p>
<%= f.label :photo_id %><br />
<%= f.text_field :photo_id %>
</p>
<p>
<%= f.label :base_colour %><br />
<%= f.text_field :base_colour %>
</p>
<p>
<%= f.submit 'Update' %>
</p>
<% end %>
<%= link_to 'Show', @category %> |
<%= link_to 'Back', categories_path %>

View File

@ -0,0 +1,14 @@
<div class="sg-24 sgParent">
<% @categories.each do |category| %>
<div class="sg-8 sgParent">
<div class="category sg-7" style="background: <%= category.base_colour %>">
<%= link_to '<h3>'+h(category.name.downcase)+'</h3>', category_photos_path(category) %>
</div>
</div>
<% end %>
<div class="sg-7 category blank-category">
</div>
</div>

View File

@ -0,0 +1,27 @@
<h1>New category</h1>
<% form_for(@category) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<p>
<%= f.label :photo_id %><br />
<%= f.text_field :photo_id %>
</p>
<p>
<%= f.label :base_colour %><br />
<%= f.text_field :base_colour %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>
<%= link_to 'Back', categories_path %>

View File

@ -0,0 +1,18 @@
<p>
<b>Name:</b>
<%=h @category.name %>
</p>
<p>
<b>Description:</b>
<%=h @category.description %>
</p>
<p>
<b>Photo:</b>
<%=h @category.photo_id %>
</p>
<%= link_to 'Edit', edit_category_path(@category) %> |
<%= link_to 'Back', categories_path %>

View File

@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Categories: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= notice %></p>
<%= yield %>
</body>
</html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,11 @@
<% if @category %>
<div class="sg-5 category" style="background: <%= @category.base_colour %>">
<h3><%=h @category.name.downcase %></h3>
</div>
<% end %>
<% @photos.each do |photo| %>
<div class="sg-5 image140"><%= link_to image_tag(photo.photo.url(:thumb)), photo.photo.url(:large), :rel => 'photo', :class => 'fancy' %></div>
<div class="sg-5 photo" style="background: url('<%= photo.photo.url(:size5) %>')"><%= link_to '&nbsp;', photo.photo.url, :rel => 'photo', :class => 'fancy' %></div>
<% end %>

View File

@ -6,6 +6,10 @@
<%= f.label :image_file %>:<br />
<%= f.file_field :photo %>
</p>
<p>
<%= f.label :category %>
<%= f.select :category_id, @categories %>
</p>
<p>
<%= submit_tag 'Upload' %>
</p>

View File

@ -1 +1 @@
<%= link_to image_tag(@photo.photo.url(:thumb)), @photo.photo.url(:large) %>
<%= link_to image_tag(@photo.photo.url(:size11)), @photo.photo.url %>

View File

@ -1,7 +1,4 @@
ActionController::Routing::Routes.draw do |map|
map.resources :photos
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
@ -41,6 +38,9 @@ ActionController::Routing::Routes.draw do |map|
# Install the default routes as the lowest priority.
# Note: These default routes make all actions in every controller accessible via GET requests. You should
# consider removing or commenting them out if you're using named routes and resources.
map.resources :categories, :has_many => :photos
map.resources :photos
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
class AddPhotoToCategory < ActiveRecord::Migration
def self.up
add_column :categories, :photo_id, :integer
end
def self.down
remove_column :categories, :photo_id
end
end

View File

@ -0,0 +1,11 @@
class AddDetailsToPhoto < ActiveRecord::Migration
def self.up
add_column :photos, :title, :string
add_column :photos, :description, :text
end
def self.down
remove_column :photos, :title
remove_column :photos, :description
end
end

View File

@ -0,0 +1,9 @@
class AddColourToCategory < ActiveRecord::Migration
def self.up
add_column :categories, :base_colour, :string
end
def self.down
remove_column :categories, :base_colour
end
end

View File

@ -0,0 +1,11 @@
class AddSortOrders < ActiveRecord::Migration
def self.up
add_column :photos, :sort, :integer
add_column :categories, :sort, :integer
end
def self.down
remove_column :photos, :sort
remove_column :categories, :sort
end
end

View File

@ -9,13 +9,16 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20101006095457) do
ActiveRecord::Schema.define(:version => 20101008122736) do
create_table "categories", :force => true do |t|
t.string "name"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "photo_id"
t.string "base_colour"
t.integer "sort"
end
create_table "photos", :force => true do |t|
@ -27,6 +30,9 @@ ActiveRecord::Schema.define(:version => 20101006095457) do
t.datetime "photo_updated_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "title"
t.text "description"
t.integer "sort"
end
end

File diff suppressed because it is too large Load Diff

BIN
public/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,11 @@
body {
background: black;
color: white;
font-family: "Helvetica Neue", "Arial", "Helvatica", sans-serif;
font-size: 14px;
}
a {
text-decoration: none;
}
#container {
padding-top: 20px;
@ -19,8 +25,44 @@ body {
bottom: 15px;
right: 20px;
}
.image140 {
.sg-5 {
height: 140px;
}
.sg-5 a {
height: 140px;
width: 140px;
}
.sg-7 {
height: 196px;
}
.sg-7 a {
height: 196px;
width: 196px;
}
.category {
position: relative;
}
.category a, .photo a {
display: block;
color: white;
text-decoration: none;
}
.category a:focus, .photo a:focus {
background: rgba(255,255,255,0.1);
}
.category a:hover, .photo a:hover {
background: rgba(255,255,255,0.2);
}
.blank-category {
background: #222;
outline: 1px dashed #444;
}
.category h3 {
position: absolute;
top: 10px;
right: 20px;
font-weight: normal;
font-size: 1.1em;
}
img {
}

View File

@ -0,0 +1,54 @@
body { background-color: #fff; color: #333; }
body, p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}
pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}
a { color: #000; }
a:visited { color: #666; }
a:hover { color: #fff; background-color:#000; }
.fieldWithErrors {
padding: 2px;
background-color: red;
display: table;
}
#errorExplanation {
width: 400px;
border: 2px solid red;
padding: 7px;
padding-bottom: 12px;
margin-bottom: 20px;
background-color: #f0f0f0;
}
#errorExplanation h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
background-color: #c00;
color: #fff;
}
#errorExplanation p {
color: #333;
margin-bottom: 0;
padding: 5px;
}
#errorExplanation ul li {
font-size: 12px;
list-style: square;
}

BIN
public/system/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,45 @@
require 'test_helper'
class CategoriesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:categories)
end
test "should get new" do
get :new
assert_response :success
end
test "should create category" do
assert_difference('Category.count') do
post :create, :category => { }
end
assert_redirected_to category_path(assigns(:category))
end
test "should show category" do
get :show, :id => categories(:one).to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => categories(:one).to_param
assert_response :success
end
test "should update category" do
put :update, :id => categories(:one).to_param, :category => { }
assert_redirected_to category_path(assigns(:category))
end
test "should destroy category" do
assert_difference('Category.count', -1) do
delete :destroy, :id => categories(:one).to_param
end
assert_redirected_to categories_path
end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class CategoriesHelperTest < ActionView::TestCase
end