Skip to content

Instantly share code, notes, and snippets.

@urbanautomaton
Created March 22, 2011 14:40
Show Gist options
  • Save urbanautomaton/881306 to your computer and use it in GitHub Desktop.
Save urbanautomaton/881306 to your computer and use it in GitHub Desktop.
Simple Paperclip Processor to timestamp attachment filenames on upload
module Paperclip
class TimeStamper < Processor
def initialize(file, options={}, attachment=nil)
super(file,options,attachment)
timestamp_filename
end
def timestamp_filename
original_filename = attachment.instance_read(:file_name)
extension = File.extname(original_filename)
date_format = @attachment.options[:date_format] ||
"%Y%m%d%H%M%S"
timestamp = DateTime.now.strftime(date_format)
new_filename = "#{timestamp}-#{original_filename}"
@attachment.instance_write(:file_name, new_filename)
end
def make
@file
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment