Skip to content

Instantly share code, notes, and snippets.

@staycreativedesign
Created August 28, 2018 17:52
Show Gist options
  • Save staycreativedesign/f0348ade84aeae4140a25f62de2df527 to your computer and use it in GitHub Desktop.
Save staycreativedesign/f0348ade84aeae4140a25f62de2df527 to your computer and use it in GitHub Desktop.
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