From cf3933271a39c0d3c5310a3c80e50323d6886c10 Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 29 Dec 2014 10:18:12 +0100 Subject: [PATCH] added profile_picture to users --- app/models/user.rb | 3 ++ ...add_attachment_profile_picture_to_users.rb | 11 ++++++ db/schema.rb | 36 ++++++++++--------- 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20141229085904_add_attachment_profile_picture_to_users.rb diff --git a/app/models/user.rb b/app/models/user.rb index 4a805a4d..b79c6d52 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,6 +40,9 @@ class User < ActiveRecord::Base # validates :website, format: { with: WEBSITE_REGEX } + has_attached_file :profile_picture, styles: { medium: "256x256>", thumb: "80x80>" }, default_url: "/images/:style/no_avatar.png" + validates_attachment_content_type :profile_picture, :content_type => /\Aimage\/.*\Z/ + before_save do self.display_name = 'WRYYYYYYYY' if display_name == 'Dio Brando' self.website = if website.match %r{\Ahttps?://} diff --git a/db/migrate/20141229085904_add_attachment_profile_picture_to_users.rb b/db/migrate/20141229085904_add_attachment_profile_picture_to_users.rb new file mode 100644 index 00000000..5191d385 --- /dev/null +++ b/db/migrate/20141229085904_add_attachment_profile_picture_to_users.rb @@ -0,0 +1,11 @@ +class AddAttachmentProfilePictureToUsers < ActiveRecord::Migration + def self.up + change_table :users do |t| + t.attachment :profile_picture + end + end + + def self.down + remove_attachment :users, :profile_picture + end +end diff --git a/db/schema.rb b/db/schema.rb index a939558f..43379d45 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141228202825) do +ActiveRecord::Schema.define(version: 20141229085904) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -133,12 +133,12 @@ ActiveRecord::Schema.define(version: 20141228202825) do add_index "smiles", ["user_id"], name: "index_smiles_on_user_id", using: :btree 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", 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, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" @@ -146,19 +146,23 @@ ActiveRecord::Schema.define(version: 20141228202825) do t.datetime "created_at" t.datetime "updated_at" t.string "screen_name" - t.integer "friend_count", default: 0, null: false - t.integer "follower_count", default: 0, null: false - t.integer "asked_count", default: 0, null: false - t.integer "answered_count", default: 0, null: false - t.integer "commented_count", default: 0, null: false + t.integer "friend_count", default: 0, null: false + t.integer "follower_count", default: 0, null: false + t.integer "asked_count", default: 0, null: false + t.integer "answered_count", default: 0, null: false + t.integer "commented_count", default: 0, null: false t.string "display_name" - t.integer "smiled_count", default: 0, null: false - t.boolean "admin", default: false, null: false - t.string "motivation_header", default: "", null: false - t.string "website", default: "", null: false - t.string "location", default: "", null: false - t.text "bio", default: "", null: false - t.boolean "moderator", default: false, null: false + t.integer "smiled_count", default: 0, null: false + t.boolean "admin", default: false, null: false + t.string "motivation_header", default: "", null: false + t.string "website", default: "", null: false + t.string "location", default: "", null: false + t.text "bio", default: "", null: false + t.boolean "moderator", default: false, null: false + t.string "profile_picture_file_name" + t.string "profile_picture_content_type" + t.integer "profile_picture_file_size" + t.datetime "profile_picture_updated_at" end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree