Skip to content

Instantly share code, notes, and snippets.

@epoch
Forked from achiurizo/photo.rb
Created January 12, 2011 21:28
Show Gist options
  • Save epoch/776922 to your computer and use it in GitHub Desktop.
Save epoch/776922 to your computer and use it in GitHub Desktop.
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
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