Skip to content

Instantly share code, notes, and snippets.

@Archimidis
Last active December 24, 2015 11:29
Show Gist options
  • Save Archimidis/6791103 to your computer and use it in GitHub Desktop.
Save Archimidis/6791103 to your computer and use it in GitHub Desktop.
Paperclip wrong attachment url on validation errors: http://stackoverflow.com/a/5995636/2425581
class ModelName
# declare papaerclip :avatar file
# ...
after_validation :avatar_reverted?
def avatar_reverted?
unless self.errors[:avatar_file_size].blank? or self.errors[:avatar_content_type].blank?
self.avatar.instance_write(:file_name, self.avatar_file_name_was)
self.avatar.instance_write(:file_size, self.avatar_file_size_was)
self.avatar.instance_write(:content_type, self.avatar_content_type_was)
end
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment