URL validation

Hello everybody,

I’m trying to link some files from some servers like Sharepoint to my

my problem is when the link is not good, I’m redirected in a 404 error
page (which is normal :p).

I would like to know how to something like a validation method to
display the button to download if the link is correct and to display a
red button if it’s not.

I tried some different things like :

def remote_file_exist?(url)
res = Net::HTTP.get_response(URI.parse(url)) rescue SocketError

Without success. Each time some files were considered as unvalide
while they were valid and vice versa.

It maybe comes from my code, that’s why i continue to try other

Any idea or suggestion ?

Here’s a gem based on an earlier plugin for this sort of thing:

It’s not without issues though. The big one is that URLs these days
can have unicode in them and the URI library (at least in Ruby 1.8.7)
treats them as invalid. Feel free to fork and improve.


On Mon, Jan 31, 2011 at 11:10 PM, agathe begault