Commit 0ea183c9

mo k <mo@mokhan.ca>
2012-10-08 21:48:15
bring back the image uploader on creation so that the migration script can convert from the ImageUploader to the PhotoUploader.
1 parent 3e07f32
app/models/creation.rb
@@ -6,6 +6,7 @@ class Creation < ActiveRecord::Base
   has_and_belongs_to_many :categories, :join_table => 'creations_categories', :uniq => true, :autosave => true
   has_many :photos, :dependent => :destroy
   has_many :favorites, :dependent => :destroy
+  mount_uploader :image, ImageUploader
 
   default_scope order("created_at DESC")
 
@@ -26,7 +27,7 @@ class Creation < ActiveRecord::Base
   end
 
   def primary_image
-    photos.first
+    photos.where(:is_primary => true).first
   end
 
   def main_image_thumb_url
app/models/photo.rb
@@ -19,4 +19,7 @@ class Photo < ActiveRecord::Base
   #def cropping?
     #!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
   #end
+  def to_s
+    "#{id} #{image}"
+  end
 end
app/views/home/index.html.erb
@@ -24,7 +24,7 @@
         <div class="carousel-inner">
           <% @creations.each_with_index do |creation, index| %>
             <div class="item<%= index == 0 ?  ' active' : ''-%>">
-              <img alt="<%= creation.name %>" src="<%= creation.image.large.url %>" style="display:block; margin-left:auto; margin-right:auto;" />
+              <img alt="<%= creation.name %>" src="<%= creation.primary_image.image.large.url %>" style="display:block; margin-left:auto; margin-right:auto;" />
               <div class="carousel-caption">
                 <h4><a href="<%= url_for creation %>"><%= creation.name %></a></h4>
                 <p><%= creation.story %></p>
@@ -79,7 +79,7 @@
       <% @creations.each do |creation| %>
         <li class="span3">
         <div class="thumbnail">
-          <a href="<%= creation.image.large.url %>" class="gallery" title="<%= creation.name %> - <%= creation.story %> "><img src="<%= creation.image.thumb.url %>" alt="<%= creation.name %>" style="width:260px;height:180px;" /></a>
+          <a href="<%= creation.primary_image.image.large.url %>" class="gallery" title="<%= creation.name %> - <%= creation.story %> "><img src="<%= creation.primary_image.image.thumb.url %>" alt="<%= creation.name %>" style="width:260px;height:180px;" /></a>
           <div class="caption">
             <h5><a href="<%= url_for creation %>"><%= short_name(creation, 20) %></a></h5>
             <h6><a href="<%= url_for profile_path(creation.user) %>"><%= shrink(creation.user.name, 20) %></a></h6>
db/migrate/20121007153155_migrate_images_to_photos.rb
@@ -2,7 +2,12 @@ class MigrateImagesToPhotos < ActiveRecord::Migration
   def up
     add_column :photos, :is_primary, :boolean
 
+    Photo.all.each do |photo|
+      photo.image.recreate_versions!
+    end
+
     Creation.all.each_with_index do |creation, index|
+      puts "#{index}. processing #{creation.name}"
       photo = creation.photos.build({:is_primary => true})
       photo.created_at = creation.created_at
       photo.updated_at = creation.updated_at
db/schema.rb
@@ -29,18 +29,18 @@ ActiveRecord::Schema.define(:version => 20121007153155) 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 => 20121007153155) 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 => 20121007153155) 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
@@ -112,8 +112,8 @@ ActiveRecord::Schema.define(:version => 20121007153155) 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|
@@ -125,8 +125,8 @@ ActiveRecord::Schema.define(:version => 20121007153155) 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"
   end
 
@@ -160,18 +160,18 @@ ActiveRecord::Schema.define(:version => 20121007153155) 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"