0
0
Fork 0

Uploads for admin site settings (#4913)

* Improve OpenGraph tags for about pages

* Add thumbnail admin setting

* Fix error

* Fix up
This commit is contained in:
Eugen Rochko 2017-09-14 00:04:30 +02:00 committed by GitHub
parent 06f26e09b4
commit 9239e4ce4d
16 changed files with 123 additions and 28 deletions

44
app/models/site_upload.rb Normal file
View file

@ -0,0 +1,44 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: site_uploads
#
# id :integer not null, primary key
# var :string default(""), not null
# file_file_name :string
# file_content_type :string
# file_file_size :integer
# file_updated_at :datetime
# meta :json
# created_at :datetime not null
# updated_at :datetime not null
#
class SiteUpload < ApplicationRecord
has_attached_file :file
validates_attachment_content_type :file, content_type: /\Aimage\/.*\z/
validates :var, presence: true, uniqueness: true
before_save :set_meta
after_commit :clear_cache
def cache_key
"site_uploads/#{var}"
end
private
def set_meta
tempfile = file.queued_for_write[:original]
return if tempfile.nil?
geometry = Paperclip::Geometry.from_file(tempfile)
self.meta = { width: geometry.width.to_i, height: geometry.height.to_i }
end
def clear_cache
Rails.cache.delete(cache_key)
end
end