diff --git a/.gitignore b/.gitignore index bab620d..f0774c3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ # Ignore Byebug command history file. .byebug_history + +# Ignore application configuration +/config/application.yml diff --git a/Gemfile b/Gemfile index 2fbc318..1cd4e32 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,9 @@ gem 'rmagick' gem "animate-rails" gem 'best_in_place', '~> 3.0.1' gem 'simple_form' +gem 'carrierwave' +gem "fog-aws" +gem "figaro" # Use Capistrano for deployment # gem 'capistrano-rails', group: :development diff --git a/Gemfile.lock b/Gemfile.lock index 156d366..9bc3044 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,11 +69,31 @@ GEM responders warden (~> 1.2.3) erubis (2.7.0) + excon (0.50.1) execjs (2.7.0) ffi (1.9.14) + figaro (1.1.1) + thor (~> 0.14) + fog-aws (0.9.4) + fog-core (~> 1.38) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) + fog-core (1.42.0) + builder + excon (~> 0.49) + formatador (~> 0.2) + fog-json (1.0.2) + fog-core (~> 1.0) + multi_json (~> 1.10) + fog-xml (0.1.2) + fog-core + nokogiri (~> 1.5, >= 1.5.11) + formatador (0.2.5) globalid (0.3.7) activesupport (>= 4.1.0) i18n (0.7.0) + ipaddress (0.8.3) jbuilder (2.6.0) activesupport (>= 3.0.0, < 5.1) multi_json (~> 1.2) @@ -194,6 +214,8 @@ DEPENDENCIES carrierwave coffee-rails (~> 4.2) devise + figaro + fog-aws jbuilder (~> 2.5) jquery-rails jquery-ui-rails diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb index 35796e0..fe3bcae 100644 --- a/app/uploaders/avatar_uploader.rb +++ b/app/uploaders/avatar_uploader.rb @@ -7,7 +7,6 @@ class AvatarUploader < CarrierWave::Uploader::Base # include CarrierWave::MiniMagick #include CarrierWave::MiniMagick # Choose what kind of storage to use for this uploader: - storage :file # storage :fog # Override the directory where uploaded files will be stored. @@ -16,6 +15,13 @@ def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end + + if Rails.env.production? + storage :fog + else + storage :file + end + def default_url ActionController::Base.helpers.asset_path([version_name, "empty.jpg"].compact.join('_')) end diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb new file mode 100644 index 0000000..fa58b78 --- /dev/null +++ b/config/initializers/carrierwave.rb @@ -0,0 +1,24 @@ +# config/initializers/carrierwave.rb + +CarrierWave.configure do |config| + config.storage = :fog + 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['AWS_ACCESS_KEY_ID'], + :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'], + :region => ENV['AWS_REGION'] + } + + + config.fog_directory = ENV['AWS_BUCKET'] + # Generate http:// urls. Defaults to :authenticated_read (https://) +end diff --git a/public/uploads/user/avatar/1/Alex.png b/public/uploads/user/avatar/1/Alex.png new file mode 100644 index 0000000..6dd76d8 Binary files /dev/null and b/public/uploads/user/avatar/1/Alex.png differ diff --git a/public/uploads/user/avatar/1/avatar_Alex.png b/public/uploads/user/avatar/1/avatar_Alex.png new file mode 100644 index 0000000..50d8ebe Binary files /dev/null and b/public/uploads/user/avatar/1/avatar_Alex.png differ diff --git a/public/uploads/user/avatar/1/mini_Alex.png b/public/uploads/user/avatar/1/mini_Alex.png new file mode 100644 index 0000000..d045fff Binary files /dev/null and b/public/uploads/user/avatar/1/mini_Alex.png differ diff --git a/public/uploads/user/avatar/1/slider_Alex.png b/public/uploads/user/avatar/1/slider_Alex.png new file mode 100644 index 0000000..95ee6d3 Binary files /dev/null and b/public/uploads/user/avatar/1/slider_Alex.png differ