I allow posting videos to youtube in my app. But before I let them save
into the DB I want to, at least, know that the users put a link to
youtube and that the link is working.
url = ‘http://www.youtube.com/foobar-blarg’
begin
result = Net::HTTP.get_response(URI.parse(url))
rescue
puts ‘Found an error’ # eg cant connect to domain
exit
end
puts ‘Not found’ if result.is_a?(Net::HTTPNotFound)
Then I can find the youtube from the uri and exit if not from that site.
I have tested your suggested code and succesfully gave me "found an
error" when I entered nonsense as url.
But then I also got "found an error" when the url was ok or non
existent. The controller spend around 30 seconds and then gave me the
same error. I just copy pasted, I must be doing something wrong...