Skip to content

Instantly share code, notes, and snippets.

@vgdub
Forked from cblunt/Gemfile
Created February 24, 2014 22:56
Show Gist options
  • Select an option

  • Save vgdub/9199056 to your computer and use it in GitHub Desktop.

Select an option

Save vgdub/9199056 to your computer and use it in GitHub Desktop.

Revisions

  1. @cblunt cblunt revised this gist Nov 17, 2011. 2 changed files with 25 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions avatar_image_uploader.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    class AvatarImageUploader < CarrierWave::Uploader::Base
    include CarrierWave::MiniMagick

    def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end

    version :print do
    version :thumb { process :resize_to_fit => [32, 32] }
    version :preview { process :resize_to_fit => [256, 256] }
    version :full { process :resize_to_fit => [2048, 2048] }
    end

    version :web do
    version :thumb { process :resize_to_fit => [32, 32] }
    version :preview { process :resize_to_fit => [128, 128] }
    version :full { process :resize_to_fit => [1024, 768] }
    end

    # ...
    end
    4 changes: 4 additions & 0 deletions show.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <!-- Nested Versions -->
    <%= image_tag avatar.avatar_image.url(:web, :preview) %>
    <%= image_tag avatar.avatar_image.url(:print, :full) %>
    <%= image_tag avatar.avatar_image.url(:web, :thumb) %>
  2. @cblunt cblunt revised this gist Nov 17, 2011. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions avatar.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    class Avatar < ActiveRecord::Base
    mount_uploader :avatar_image, AvatarImageUploader # **must** specify class of uploader, otherwise base uploader is used, and no

    # ...
    end
  3. @cblunt cblunt renamed this gist Oct 21, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions configinitializerscarrierwave.rb → carrierwave.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # config/initializers/carrierwave.rb

    CarrierWave.configure do |config|
    config.fog_credentials = {
    # Configuration for Amazon S3 should be made available through an Environment variable.
  4. @cblunt cblunt created this gist Oct 21, 2011.
    4 changes: 4 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # ...

    gem 'carrierwave'
    gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
    32 changes: 32 additions & 0 deletions configinitializerscarrierwave.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    CarrierWave.configure do |config|
    config.fog_credentials = {
    # Configuration for Amazon S3 should be made available through an Environment variable.
    # For local installations, export the env variable through the shell OR
    # if using Passenger, set an Apache environment variable.
    #
    # In Heroku, follow http://devcenter.heroku.com/articles/config-vars
    #
    # $ heroku config:add S3_KEY=your_s3_access_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_ASSET_URL=http://assets.example.com/ S3_BUCKET_NAME=s3_bucket/folder

    # Configuration for Amazon S3
    :provider => 'AWS',
    :aws_access_key_id => ENV['S3_KEY'],
    :aws_secret_access_key => ENV['S3_SECRET'],
    :region => ENV['S3_REGION']
    }

    # For testing, upload files to local `tmp` folder.
    if Rails.env.test? || Rails.env.cucumber?
    config.storage = :file
    config.enable_processing = false
    config.root = "#{Rails.root}/tmp"
    else
    config.storage = :fog
    end

    config.cache_dir = "#{Rails.root}/tmp/uploads" # To let CarrierWave work on heroku

    config.fog_directory = ENV['S3_BUCKET_NAME']
    config.s3_access_policy = :public_read # Generate http:// urls. Defaults to :authenticated_read (https://)
    config.fog_host = "#{ENV['S3_ASSET_URL']}/#{ENV['S3_BUCKET_NAME']}"
    end