Created
August 28, 2018 17:52
-
-
Save staycreativedesign/f0348ade84aeae4140a25f62de2df527 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class GraphicUploader < Shrine | |
include ImageProcessing::MiniMagick | |
plugin :activerecord | |
plugin :cached_attachment_data # for retaining the cached file across form redisplays | |
plugin :restore_cached_data # re-extract metadata when attaching a cached file | |
plugin :determine_mime_type | |
plugin :remove_attachment | |
def generate_location(io, context = {}) | |
name = super # the default unique identifier | |
if io.is_a?(File) | |
initial_location = io.to_path | |
new_location = initial_location.match(/(.*\/).*/)[1] | |
final_location = [new_location + name].compact.join # returns original path | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment