Skip to content

Instantly share code, notes, and snippets.

@gabrielbidula
Created March 7, 2016 21:25
Show Gist options
  • Save gabrielbidula/56a34c979fdf32a9f265 to your computer and use it in GitHub Desktop.
Save gabrielbidula/56a34c979fdf32a9f265 to your computer and use it in GitHub Desktop.
def rename_photos
images.each do |image|
extension = File.extname(image.attachment_file_name).downcase
old_file_name = image.attachment_file_name
new_file_name = slug+"-"+"#{image.position}"+"#{extension}"
image.attachment_file_name = new_file_name
(image.attachment.styles.keys+[:original]).each do |style|
FileUtils.move(File.join(File.dirname(image.attachment.path(style)), old_file_name), image.attachment.path(style))
end
image.save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment