Created
May 25, 2016 17:18
-
-
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.
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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