Commit 29346486

mo k <mo@mokhan.ca>
2012-08-08 03:35:29
create avatar
1 parent de17371
app/models/avatar.rb
@@ -0,0 +1,4 @@
+class Avatar < ActiveRecord::Base
+  belongs_to :user
+  mount_uploader :avatar, AvatarUploader
+end
app/models/user.rb
@@ -8,7 +8,7 @@ class User < ActiveRecord::Base
   has_many :favorites, :dependent => :destroy
   has_many :authentications
   has_and_belongs_to_many :interests, :join_table => 'users_interests', :uniq => true, :autosave => true
-  mount_uploader :avatar, AvatarUploader
+  has_one :avatar
 
   def add_favorite( creation )
     if self.already_likes(creation)
db/migrate/20120717123632_add_is_restricted_to_creation.rb
@@ -1,8 +1,5 @@
 class AddIsRestrictedToCreation < ActiveRecord::Migration
   def change
     add_column :creations, :is_restricted, :boolean, :default => false, :null => false
-    Creation.joins(:categories).where(:categories => {:slug => 'Naughty Cakes'}).each do |creation|
-      creation.update_attributes! :is_restricted => true
-    end
   end
 end
db/migrate/20120808025315_add_avatar_to_users.rb
@@ -1,5 +0,0 @@
-class AddAvatarToUsers < ActiveRecord::Migration
-  def change
-    add_column :users, :avatar, :string
-  end
-end
db/migrate/20120808032550_create_avatars.rb
@@ -0,0 +1,9 @@
+class CreateAvatars < ActiveRecord::Migration
+  def change
+    create_table :avatars do |t|
+      t.integer :user_id
+
+      t.timestamps
+    end
+  end
+end
db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20120808025315) do
+ActiveRecord::Schema.define(:version => 20120808032550) do
 
   create_table "active_admin_comments", :force => true do |t|
     t.integer  "resource_id",   :null => false
@@ -46,6 +46,12 @@ ActiveRecord::Schema.define(:version => 20120808025315) do
   add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
   add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
 
+  create_table "avatars", :force => true do |t|
+    t.integer  "user_id"
+    t.datetime "created_at", :null => false
+    t.datetime "updated_at", :null => false
+  end
+
   create_table "categories", :force => true do |t|
     t.string   "name"
     t.datetime "created_at", :null => false
@@ -125,7 +131,6 @@ ActiveRecord::Schema.define(:version => 20120808025315) do
     t.string   "city"
     t.float    "latitude"
     t.float    "longitude"
-    t.string   "avatar"
   end
 
   add_index "users", ["email"], :name => "index_users_on_email", :unique => true
spec/models/avatar_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Avatar do
+  pending "add some examples to (or delete) #{__FILE__}"
+end