Skip to content

Instantly share code, notes, and snippets.

@ewalk153
Created June 5, 2015 16:21
Show Gist options
  • Save ewalk153/8661b5e13792a62cccdd to your computer and use it in GitHub Desktop.
Save ewalk153/8661b5e13792a62cccdd to your computer and use it in GitHub Desktop.
Console script to find bad paperclip image uploads and fix them.
def head_status(u)
uri = URI(u)
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
request = Net::HTTP::Head.new uri
response = http.request request # Net::HTTPResponse object
response.code
end
end
UnitImage.all.select{|i| head_status(i.image.url('small')) == '403' }.each{|i| puts i }.map{|i| i.image.reprocess! }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment