Skip to content

How to: Use a timestamp in file names

porras edited this page Sep 28, 2011 · 5 revisions

You can include a timestamp in filenames overriding the filename as you can read in Carrierwave docs:

class PhotoUploader < CarrierWave::Uploader::Base
  def filename
     @name ||= "#{Time.now.to_i}-#{super}" if super.present?
  end
end

Don't forget to memoize the result in an instance variable or you might get different timestamps written to the database and the file store.

(Related: How to: Create random and unique filenames for all versioned files)

Clone this wiki locally