Skip to content

Instantly share code, notes, and snippets.

@kjlape
Created May 25, 2016 17:18
Show Gist options
  • Select an option

  • Save kjlape/663310e1cdcf3fe287df74d5a2fc95b0 to your computer and use it in GitHub Desktop.

Select an option

Save kjlape/663310e1cdcf3fe287df74d5a2fc95b0 to your computer and use it in GitHub Desktop.
If for some crazy reason you need to find all ActiveRecord models with off-server hosted, carrierwave uploaded files, this is just the thing for you.
bad_models = FlakyImage.select do |image|
uri = URI.parse image.file.url
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
response = http.head uri.path
response.code != "200"
end
end
bad_models.count
class FlakyImage < ActiveRecord::Base
mount_uploader :file, FlakyImageUploader
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment