Class: Paperclip::FilenameCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip_patch.rb

Instance Method Summary collapse

Instance Method Details

#call(filename) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/paperclip_patch.rb', line 8

def call(filename)
  # Dirty hack to keep the dot in the filename (it's removed by the parameterize function)
  placeholder = '-p-l-a-c-e-h-o-l-d-e-r-'
  filename.sub!('.', placeholder)
  filename = filename.parameterize()
  filename.sub!(placeholder, '.')

  if @invalid_character_regex
    filename = filename.gsub(@invalid_character_regex, "_").gsub("_", "-")
  else
    filename
  end
end