Skip to content

Instantly share code, notes, and snippets.

@alfielapeter
Created November 18, 2010 22:08
Show Gist options
  • Save alfielapeter/705742 to your computer and use it in GitHub Desktop.
Save alfielapeter/705742 to your computer and use it in GitHub Desktop.
# return a sanitized version of the image filename
# (remove spaces, etc.) and then determine position
# based on filename (eg. 1.jpg, 2.jpg)
def sanitize_and_position_photo
filename = self.image_file_name
ext = File.extname(filename)
just_filename = File.basename(filename, ext)
unless just_filename.to_i == 0
self.position = just_filename.to_i
end
self.image_file_name = just_filename.gsub(/\W+/,'_') + ext
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment