Checking URL with open-uri

Hi,

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.

How can I do those verifications with open-uri?

Tried but got some errors...

Thanks.

Using ‘net/http’ you can:

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)

Thanks Phil!

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...

Thanks.

Hi,

I fixed the problem I needed either to add a proxy or missed a require
8-P

Cheers

comopasta Gr wrote:

Hi,

I fixed the problem I needed either to add a proxy or missed a require
8-P

Cheers

can write the detail code ? ,thanks