Created
July 8, 2010 20:33
-
-
Save achiurizo/468577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'carrierwave/orm/mongoid' | |
class Photo | |
include Mongoid::Document | |
include Mongoid::Timestamps # adds created_at and updated_at fields | |
# fields | |
field :caption, :type => String | |
mount_uploader :file, Uploader | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Uploader < CarrierWave::Uploader::Base | |
## | |
# Image manipulator library: | |
# | |
include CarrierWave::RMagick | |
# include CarrierWave::ImageScience | |
# include CarrierWave::MiniMagick | |
## | |
# Storage type | |
# | |
storage :file | |
# | |
# configure do |config| | |
# config.s3_access_key_id = 'AKIAJBPCWSJNLHOPAKDQ' | |
# config.s3_secret_access_key = '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' | |
# config.s3_bucket = 'assets-web' | |
# end | |
# | |
# storage :right_s3 | |
## | |
# Directory where uploaded files will be stored (default is /public/uploads) | |
# | |
def store_dir | |
"images/uploads" | |
end | |
def root | |
File.join(Padrino.root,"public/") | |
end | |
## | |
# Directory where uploaded temp files will be stored (default is [root]/tmp) | |
# | |
def cache_dir | |
Padrino.root("tmp") | |
end | |
## | |
# Default URL as a default if there hasn't been a file uploaded | |
# | |
# def default_url | |
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') | |
# end | |
## | |
# Process files as they are uploaded. | |
# | |
process :convert => 'png' | |
version :thumb do | |
process :convert => 'png' | |
process :resize_to_fill => [100, 100] | |
end | |
# | |
# def scale(width, height) | |
# # do something | |
# end | |
## | |
# Create different versions of your uploaded files | |
# | |
# version :header do | |
# process :resize_to_fill => [940, 250] | |
# version :thumb do | |
# process :resize_to_fill => [230, 85] | |
# end | |
# end | |
## | |
# White list of extensions which are allowed to be uploaded: | |
# | |
def extension_white_list | |
%w(jpg jpeg gif png) | |
end | |
## | |
# Override the filename of the uploaded files | |
# | |
# def filename | |
# "something.jpg" if original_filename | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment