Add RMagick gem and initial version of CarrierWave's uploader.
This commit is contained in:
parent
67456bb979
commit
8aab5fe93b
3 changed files with 65 additions and 0 deletions
4
Gemfile
4
Gemfile
|
|
@ -22,6 +22,10 @@ gem 'cancan', '1.6.5'
|
|||
# Deploy with Capistrano
|
||||
gem 'capistrano', '2.5.21'
|
||||
|
||||
# For avatar images: https://github.com/jnicklas/carrierwave
|
||||
gem 'rmagick', '2.9.2'
|
||||
gem 'carrierwave', '0.6.2'
|
||||
|
||||
# https://github.com/jnunemaker/twitter
|
||||
gem 'twitter', '2.5.0'
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ GEM
|
|||
net-sftp (>= 2.0.0)
|
||||
net-ssh (>= 2.0.14)
|
||||
net-ssh-gateway (>= 1.0.0)
|
||||
carrierwave (0.6.2)
|
||||
activemodel (>= 3.2.0)
|
||||
activesupport (>= 3.2.0)
|
||||
coffee-rails (3.2.2)
|
||||
coffee-script (>= 2.2.0)
|
||||
railties (~> 3.2.0)
|
||||
|
|
@ -138,6 +141,7 @@ GEM
|
|||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
responders (0.6.5)
|
||||
rmagick (2.9.2)
|
||||
sass (3.1.19)
|
||||
sass-rails (3.2.5)
|
||||
railties (~> 3.2.0)
|
||||
|
|
@ -174,12 +178,14 @@ DEPENDENCIES
|
|||
bourbon (= 1.4.0)
|
||||
cancan (= 1.6.5)
|
||||
capistrano (= 2.5.21)
|
||||
carrierwave (= 0.6.2)
|
||||
coffee-rails (= 3.2.2)
|
||||
devise (= 2.0.4)
|
||||
json (= 1.6.5)
|
||||
mail
|
||||
mysql2 (= 0.3.11)
|
||||
rails (= 3.2.5)
|
||||
rmagick (= 2.9.2)
|
||||
sass-rails (= 3.2.5)
|
||||
twitter (= 2.5.0)
|
||||
uglifier
|
||||
|
|
|
|||
55
app/uploaders/avatar_uploader.rb
Normal file
55
app/uploaders/avatar_uploader.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# 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/#{model.class.to_s.underscore}/#{mounted_as}/#{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('_')
|
||||
# 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 :thumb do
|
||||
# process :scale => [50, 50]
|
||||
# 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue