Add logo field to ContentConfig

This commit is contained in:
Rohan Mitchell
2015-07-14 14:54:05 +10:00
parent 4887871474
commit 1b17a7fb35
2 changed files with 45 additions and 0 deletions

View File

@@ -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

View File

@@ -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