From 1b17a7fb35d3fdb23082eb80e3e1106631c59fab Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 14 Jul 2015 14:54:05 +1000 Subject: [PATCH] Add logo field to ContentConfig --- app/models/content_configuration.rb | 10 +++++++ lib/open_food_network/paperclippable.rb | 35 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 lib/open_food_network/paperclippable.rb diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 5fd4e5e0f7..dd2e76ed8b 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -1,4 +1,14 @@ +require 'open_food_network/paperclippable' + class ContentConfiguration < Spree::Preferences::Configuration + # Header + include OpenFoodNetwork::Paperclippable + preference :logo_file_name, :string + preference :logo_content_type, :string + preference :logo_file_size, :integer + preference :logo_updated_at, :string + has_attached_file :logo + # Home page preference :home_show_stats, :boolean, default: true diff --git a/lib/open_food_network/paperclippable.rb b/lib/open_food_network/paperclippable.rb new file mode 100644 index 0000000000..a66d52211e --- /dev/null +++ b/lib/open_food_network/paperclippable.rb @@ -0,0 +1,35 @@ +# 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.send :extend, ActiveModel::Naming + base.send :extend, ActiveModel::Callbacks + base.send :include, ActiveModel::Validations + base.send :include, Paperclip::Glue + + # Paperclip required callbacks + base.send :define_model_callbacks, :save, only: [:after] + base.send :define_model_callbacks, :commit, only: [:after] + base.send :define_model_callbacks, :destroy, only: [:before, :after] + end + + # ActiveModel requirements + def to_model + self + end + + def valid?() true end + def new_record?() true end + def destroyed?() 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