Last active
December 1, 2020 19:53
-
-
Save tb/8787397 to your computer and use it in GitHub Desktop.
Check if URL exists in Ruby
This file contains 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
require 'net/http' | |
def working_url?(url_str) | |
url = URI.parse(url_str) | |
Net::HTTP.start(url.host, url.port) do |http| | |
http.head(url.request_uri).code == '200' | |
end | |
rescue | |
false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work when checking if an image URL exists.