Created
May 5, 2016 23:07
-
-
Save zaeleus/5784e0b966555c5d008ec534ad7b1501 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'shrine' | |
require 'shrine/storage/memory' | |
Shrine.storages = { | |
cache: Shrine::Storage::Memory.new, | |
store: Shrine::Storage::Memory.new | |
} | |
class DocumentUploader < Shrine | |
plugin :determine_mime_type | |
plugin :validation_helpers | |
Attacher.validate do | |
validate_mime_type_inclusion ['image/jpeg'] | |
end | |
end | |
class Document | |
include DocumentUploader[:attachment] | |
attr_accessor :attachment_data | |
end | |
document = Document.new | |
document.attachment = File.open('-image.jpg') | |
p document.attachment_attacher.errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment