Check url address

Hello all,

i would like to do something like define two urls, primary and
secondary. After that, check them and if primary is not available,
choose secondary url. At the end, put these to some variable for next
usage.

Thanks a lot! L.

Great, thank you so much :slight_smile:

On Wed, May 4, 2011 at 9:50 AM, Lukáš N. [email protected] wrote:

Hello all,

i would like to do something like define two urls, primary and
secondary. After that, check them and if primary is not available,
choose secondary url. At the end, put these to some variable for next
usage.

You can try to open the first URL and if there’s any exception, use
the second one.
Something like:

ruby-1.9.1-p431 :004 > require ‘open-uri’
=> true
ruby-1.9.1-p431 :005 > url1 = “http://fsdfsdfsdf.com
=> “http://fsdfsdfsdf.com
ruby-1.9.1-p431 :006 > url2 = “http://www.google.com
=> “http://www.google.com
ruby-1.9.1-p431 :007 > valid_url = begin
ruby-1.9.1-p431 :008 > open(url1)
ruby-1.9.1-p431 :009?> url1
ruby-1.9.1-p431 :010?> rescue
ruby-1.9.1-p431 :011?> url2
ruby-1.9.1-p431 :012?> end
=> “http://www.google.com
ruby-1.9.1-p431 :013 > valid_url
=> “http://www.google.com

Jesus.

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