I m looping through an array of URL strings of images hosted at an external site.
It looks something like this:
def get_image_urls
image_url_array.each do |image_url|
puts image_tag image_url
end
end
Which will return the URLs of images hosted on the external site. The problem is, some of these images might be broken (404). So for example:
get_image_urls
# These would return image_tags, but for brevity...
=> "http://someothersite.com/images/1.jpg"
"http://someothersite.com/images/2.jpg"
"http://someothersite.com/images/3.jpg" # <-- (Broken: 404)
"http://someothersite.com/images/4.jpg"
"http://someothersite.com/images/5.jpg" # <-- (Broken: 404)
What I m looking to do is replace the URL strings of the broken images to a "missing" image hosted on my own site. So using the example above, with 3.jpg and 5.jpg being broken, I want to have returned something like this:
get_image_urls
# These would return image_tags, but for brevity...
=> "http://someothersite.com/images/1.jpg"
"http://someothersite.com/images/2.jpg"
"http://mysite.com/images/missing.png"
"http://someothersite.com/images/4.jpg"
"http://mysite.com/images/missing.png"
Is there a simple way to solve this problem? Thanks so much in advance.