title: Replacing Broken External Images With Custom Image
body: <p>I'm looping through an array of URL strings of images hosted at an external site.</p>
  
  <p>It looks something like this:</p>
  
  <pre><code>def get_image_urls
    image_url_array.each do |image_url|
      puts image_tag image_url
    end
  end
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>get_image_urls
  # These would return image_tags, but for brevity...
  =&gt; "http://someothersite.com/images/1.jpg"
     "http://someothersite.com/images/2.jpg"
     "http://someothersite.com/images/3.jpg" # &lt;-- (Broken: 404)
     "http://someothersite.com/images/4.jpg"
     "http://someothersite.com/images/5.jpg" # &lt;-- (Broken: 404)
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>get_image_urls
  # These would return image_tags, but for brevity...
  =&gt; "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"
  </code></pre>
  
  <p>Is there a simple way to solve this problem? Thanks so much in advance.</p>