
Untitled
By: a guest on
May 26th, 2012 | syntax:
None | size: 1.12 KB | hits: 11 | expires: Never
has_attached_file :file, :styles => lambda { |media_file| media_file.instance.media_type == 'image' ? IMAGE_VERSIONS : {} },
:storage => :s3,
:path => ":storage_path",
:bucket => lambda{ |media_file| media_file.instance.bucket_name },
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:url => ":s3_eu_url"
before_save :normalize_file_file_name
# == Filename helper
Paperclip.interpolates :normalized_file_file_name do |attachment, style|
attachment.instance.normalized_file_file_name
end
def normalized_file_file_name
transliterate(self.file_file_name)
end
def normalize_file_file_name
self.file_file_name = normalized_file_file_name
end
def storage_path
if media_type == 'image'
":attachment/:id/:style/:filename"
else
":normalized_file_file_name"
end
end
def transliterate(string)
s = Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
s.downcase!
s.gsub!(/'/, '')
s.gsub!(/[^A-Za-z0-9_\.]+/, ' ')
s.strip!
s.gsub!(/\ +/, '-')
return s
end