Permalink
Browse files

add carrierwave gem and avatar to user model.

  • Loading branch information...
1 parent 3f0ab13 commit 54d914ba94c1f57552a2f963fb0dde776fc7d33e @shioyama shioyama committed Jun 2, 2012
View
@@ -27,6 +27,8 @@ gem 'globalize3', :git => 'git://github.com/svenfuchs/globalize3.git'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'twitter_bootstrap_form_for', :git => 'git://github.com/stouset/twitter_bootstrap_form_for.git', :branch => 'bootstrap-2.0'
+gem 'carrierwave'
+gem 'mini_magick'
group :test, :development do
gem 'rspec-rails'
View
@@ -64,6 +64,9 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
+ carrierwave (0.6.2)
+ activemodel (>= 3.2.0)
+ activesupport (>= 3.2.0)
childprocess (0.3.0)
ffi (~> 1.0.6)
coffee-rails (3.2.2)
@@ -123,6 +126,8 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
+ mini_magick (3.4)
+ subexec (~> 0.2.1)
multi_json (1.0.4)
nokogiri (1.5.0)
oauth (0.4.5)
@@ -192,6 +197,7 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
+ subexec (0.2.2)
term-ansicolor (1.0.7)
thor (0.14.6)
tilt (1.3.3)
@@ -212,6 +218,7 @@ DEPENDENCIES
bootstrap-sass (~> 2.0.1)
capybara
capybara-webkit!
+ carrierwave
coffee-rails (~> 3.2.1)
cucumber (>= 1.1.6)
cucumber-rails (~> 1.0)
@@ -222,6 +229,7 @@ DEPENDENCIES
haml (>= 3.1.alpha.50)
haml-rails
jquery-rails
+ mini_magick
omniauth
omniauth-twitter
rails (= 3.2.3)
View
@@ -5,6 +5,8 @@ class User < ActiveRecord::Base
has_many :cothreads
has_many :authorizations
+ mount_uploader :avatar, AvatarUploader
+
def self.new_from_hash(hash)
new(:name => hash['info']['nickname'],
:location => hash['info']['location'],
@@ -0,0 +1,56 @@
+# encoding: utf-8
+
+class AvatarUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or MiniMagick support:
+ # include CarrierWave::RMagick
+ include CarrierWave::MiniMagick
+
+ # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
+ # include Sprockets::Helpers::RailsHelper
+ # include Sprockets::Helpers::IsolatedHelper
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :fog
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/avatars/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ def default_url
+ # # For Rails 3.1+ asset pipeline compatibility:
+ # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
+ #
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+ "/images/avatar.png"
+ end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ version :mini do
+ process :resize_to_fit => [32, 32]
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+end
@@ -0,0 +1,5 @@
+class AddAvatarToUsers < ActiveRecord::Migration
+ def change
+ add_column :users, :avatar, :string
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120417082330) do
+ActiveRecord::Schema.define(:version => 20120602070944) do
create_table "authorizations", :force => true do |t|
t.string "provider"
@@ -48,6 +48,7 @@
t.string "fullname"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.string "avatar"
end
end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 54d914b

Please sign in to comment.