Created
November 18, 2010 22:08
-
-
Save alfielapeter/705742 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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