summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-10-27 21:58:23 -0600
committermo k <mo@mokhan.ca>2012-10-27 21:58:23 -0600
commit4d49df8bf3605ebec10502b798978df8db1a40cd (patch)
treecea3d818d4a2ef485917fb7b32991218a02d1633
parentb79a38e853db2b78cbaefcdd7e6f6b3bdd19c5b0 (diff)
mark the first photo uploaded as the primary image.
-rw-r--r--app/controllers/creations_controller.rb2
-rw-r--r--app/controllers/photos_controller.rb1
-rw-r--r--app/models/creation.rb6
-rw-r--r--db/schema.rb36
4 files changed, 25 insertions, 20 deletions
diff --git a/app/controllers/creations_controller.rb b/app/controllers/creations_controller.rb
index a1a082f1..a7b290e3 100644
--- a/app/controllers/creations_controller.rb
+++ b/app/controllers/creations_controller.rb
@@ -2,7 +2,7 @@ class CreationsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
# GET /creations
def index
- @creations = Creation.where(:is_restricted => false, :is_published => true).page(params[:page]).per(16)
+ @creations = Creation.where(:is_restricted => false).page(params[:page]).per(16)
end
# GET /creations/1
diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb
index 4489daa0..40f3a14e 100644
--- a/app/controllers/photos_controller.rb
+++ b/app/controllers/photos_controller.rb
@@ -18,6 +18,7 @@ class PhotosController < ApplicationController
def create
attributes = params[:photo]
attributes[:image] = params[:photo][:image].first if params[:photo][:image].class == Array
+ attributes[:is_primary] = !@creation.photos.any?
@photo = @creation.photos.build(attributes)
if @photo.save
diff --git a/app/models/creation.rb b/app/models/creation.rb
index 61c59a1d..b39ae152 100644
--- a/app/models/creation.rb
+++ b/app/models/creation.rb
@@ -21,7 +21,11 @@ class Creation < ActiveRecord::Base
end
def primary_image
- photos.where(:is_primary => true).first
+ if photos.any?
+ photos.where(:is_primary => true).first
+ else
+ Photo.new
+ end
end
def migrate_primary_image
diff --git a/db/schema.rb b/db/schema.rb
index 062bce7f..4d9fe3db 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -29,18 +29,18 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
add_index "active_admin_comments", ["resource_type", "resource_id"], :name => "index_admin_notes_on_resource_type_and_resource_id"
create_table "admin_users", :force => true do |t|
- t.string "email", :default => "", :null => false
- t.string "encrypted_password", :default => "", :null => false
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", :default => 0
+ t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
@@ -55,8 +55,8 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
create_table "categories", :force => true do |t|
t.string "name"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.string "slug"
end
@@ -80,8 +80,8 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
create_table "creations", :force => true do |t|
t.string "name"
t.text "story"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.integer "user_id"
t.string "image"
t.boolean "is_restricted", :default => false, :null => false
@@ -113,8 +113,8 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
create_table "favorites", :force => true do |t|
t.integer "user_id"
t.integer "creation_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
end
create_table "interests", :force => true do |t|
@@ -126,8 +126,8 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
create_table "photos", :force => true do |t|
t.integer "creation_id"
t.string "image"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.boolean "is_primary", :default => false
end
@@ -163,18 +163,18 @@ ActiveRecord::Schema.define(:version => 20121013031725) do
end
create_table "users", :force => true do |t|
- t.string "email", :default => "", :null => false
- t.string "encrypted_password", :default => "", :null => false
+ t.string "email", :default => "", :null => false
+ t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
- t.integer "sign_in_count", :default => 0
+ t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at"
+ t.datetime "updated_at"
t.string "name"
t.string "website"
t.string "twitter"