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.

···

--
Posted via http://www.ruby-forum.com/.

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.

···

On Wed, May 4, 2011 at 9:50 AM, Lukáš N. <dmnc.mobile@gmail.com> 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.

Great, thank you so much :slight_smile:

···

--
Posted via http://www.ruby-forum.com/.