Skip to content

Instantly share code, notes, and snippets.

@vu2
Created November 30, 2015 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vu2/0b6c99c8033bc0a8f907 to your computer and use it in GitHub Desktop.
Save vu2/0b6c99c8033bc0a8f907 to your computer and use it in GitHub Desktop.
class PhotoUploader < CarrierWave::Uploader::Base
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment