Check whether externam URL is valid?


I have users entering URLs into my app, is there anyway in which I can
check to see if the URLs actually point to something before saving the
user input? Maybe a kind of ‘ping’-action that returns true on success?

(btw: does anyone of a tentative release date for Rails1.1? I’ve been
slobbering all over my RailsRecipes book and I can’t wait! Also, Scott
Raymond’s compiled a list of awesome stuff that’ll be incorporated into
the next release. . . link on LoudThinking.Com)

Lots of Thanks,
[email protected]

mmm…Externam should read External :slight_smile: 'suppose you noticed.


Net::HTTP looks like your best shot.

require ‘net/http’
Net::HTTP.start(‘’) do |http|
response = http.get(’/index.html’)
p response.code

Check acceptable response codes here:


John S.
Computing Staff - Webmaster
Kavli Institute for Theoretical Physics
University of California, Santa Barbara
[email protected]
(805) 893-6307

Hey John,

That only works for valid URL’s. It doesn’t alert you if the URL isn’t
there. I’m not sure how to check that?

I’ve tried your code with a check on the response.

unless response == ‘200’
p ‘Site is down’
p ‘Found it!’

I get a “SocketError: getaddrinfo: No address associated with
nodename”, which isn’t checkable to my knowledge.

Any ideas?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs