Replace Paperclippable ContentConfig

The old Paperclip configuration was very clever and easy to use but it
was also a complicated implementation building on the complicated Spree
preference system.

I simplified this with Active Storage, storing simple references to blob
ids and default URLs as backup.
This commit is contained in:
Maikel Linke
2022-04-06 14:48:06 +10:00
parent ddd9ae6ce2
commit 727eef3c4f
15 changed files with 86 additions and 203 deletions

View File

@@ -1,51 +0,0 @@
# frozen_string_literal: true
# Allow use of Paperclip's has_attached_file on non-ActiveRecord classes
# https://gist.github.com/basgys/5712426
module OpenFoodNetwork
module Paperclippable
def self.included(base)
base.extend(ActiveModel::Naming)
base.extend(ActiveModel::Callbacks)
base.include(ActiveModel::Validations)
base.include(Paperclip::Glue)
# Paperclip required callbacks
base.define_model_callbacks(:save, only: [:after])
base.define_model_callbacks(:commit, only: [:after])
base.define_model_callbacks(:destroy, only: [:before, :after])
# Initialise an ID
base.__send__(:attr_accessor, :id)
base.instance_variable_set :@id, 1
end
# ActiveModel requirements
def to_model
self
end
def valid?() true end
def new_record?() true end
def destroyed?() true end
def save
run_callbacks :save do
end
true
end
def errors
obj = Object.new
def obj.[](_key) [] end
def obj.full_messages() [] end
def obj.any?() false end
obj
end
end
end