diff --git a/.gitignore b/.gitignore index 6809ebb..ce55809 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,9 @@ # Ignore environment variables .env +# Ignore Active Storage +/storage + # Ignore dragonfly uploads /public/system /public/packs diff --git a/Gemfile b/Gemfile index f7ae0a7..f12124c 100644 --- a/Gemfile +++ b/Gemfile @@ -7,8 +7,8 @@ gem "dotenv-rails", groups: %i[development test] gem "rails", "5.2.1" gem "delayed_job_active_record" -gem "dragonfly" gem "http" +gem "mini_magick" gem "omniauth-github" gem "pg" gem "puma" diff --git a/Gemfile.lock b/Gemfile.lock index a10b1af..14f53d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,10 +82,6 @@ GEM dotenv-rails (2.5.0) dotenv (= 2.5.0) railties (>= 3.2, < 6.0) - dragonfly (1.1.5) - addressable (~> 2.3) - multi_json (~> 1.0) - rack (>= 1.3) erubi (1.7.1) execjs (2.7.0) faraday (0.12.2) @@ -121,6 +117,7 @@ GEM mimemagic (~> 0.3.2) method_source (0.9.1) mimemagic (0.3.2) + mini_magick (4.9.2) mini_mime (1.0.1) mini_portile2 (2.3.0) minitest (5.11.3) @@ -266,10 +263,10 @@ DEPENDENCIES capybara delayed_job_active_record dotenv-rails - dragonfly geckodriver-helper http launchy + mini_magick omniauth-github pg pry @@ -289,4 +286,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.4 + 1.16.5 diff --git a/README.md b/README.md index b531719..6ad2828 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [ ![Codeship Status for danbee/my-images](https://app.codeship.com/projects/cf564ea0-7cbe-0136-47c4-2ebac98daaef/status?branch=master)](https://app.codeship.com/projects/300990) -A simple DragonFly powered image storage application. +A simple Active Storage powered image storage application. ![](https://user-images.githubusercontent.com/165531/43842691-e38186be-9af3-11e8-9387-d1ee206cca2e.png) diff --git a/app/helpers/image_helper.rb b/app/helpers/image_helper.rb index 62e5ec7..0298353 100644 --- a/app/helpers/image_helper.rb +++ b/app/helpers/image_helper.rb @@ -1,9 +1,15 @@ module ImageHelper + def image_variant(image, variant) + image.variant(variant) + end + def image_thumb(image, size) - if image.format == "jpeg" - image.thumb(size).encode("jpg", "-quality 90") - else - image.thumb(size) - end + image.variant( + combine_options: { + gravity: "center", + resize: "#{size}x#{size}^", + extent: "#{size}x#{size}", + }, + ) end end diff --git a/app/jobs/tag_image_job.rb b/app/jobs/tag_image_job.rb index ac84935..5a9603d 100644 --- a/app/jobs/tag_image_job.rb +++ b/app/jobs/tag_image_job.rb @@ -4,7 +4,7 @@ class TagImageJob < ApplicationJob def perform(image_id:) image = Image.find(image_id) - tags = Clarifai.new(image.image.file.path).tags + tags = Clarifai.new(image.image.download).tags image.update_attributes(tags: tags) end end diff --git a/app/models/image.rb b/app/models/image.rb index 379ff1a..abf3346 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -1,7 +1,7 @@ class Image < ActiveRecord::Base - dragonfly_accessor :image + has_one_attached :image - validates :image, presence: true + validates :image, attached: true belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index 1fcfad9..e818b79 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,4 @@ class User < ActiveRecord::Base - dragonfly_accessor :avatar - has_many :images def self.find_or_create_from_auth(auth) @@ -13,7 +11,6 @@ class User < ActiveRecord::Base uid: auth.uid, username: auth.info.nickname, name: auth.info.name, - avatar_url: auth.info.image, ) end end diff --git a/app/validators/attached_validator.rb b/app/validators/attached_validator.rb new file mode 100644 index 0000000..b860bc1 --- /dev/null +++ b/app/validators/attached_validator.rb @@ -0,0 +1,7 @@ +class AttachedValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + if !value.attached? + record.errors.add(attribute, :attached, options) + end + end +end diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index 43a3604..31ca994 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -1,17 +1,17 @@ - " + " media="(min-width: 960px) and (-webkit-min-device-pixel-ratio: 2), (min-width: 960px) and (min-resolution: 192dpi)"> - " + " media="(min-width: 960px)"> - " + " media="(min-width: 640px) and (-webkit-min-device-pixel-ratio: 2), (min-width: 640px) and (min-resolution: 192dpi)"> - " + " media="(min-width: 640px)"> - " + " media="(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)"> - "> - " itemprop="image"> + "> + " itemprop="image"> diff --git a/app/views/images/index.html.erb b/app/views/images/index.html.erb index 803ed02..6b6d926 100644 --- a/app/views/images/index.html.erb +++ b/app/views/images/index.html.erb @@ -5,7 +5,7 @@