我正在循環訪問外部網站託管的圖像的URL字符串數組。使用自定義圖像替換破碎的外部圖像
它看起來是這樣的:
def get_image_urls
image_url_array.each do |image_url|
puts image_tag image_url
end
end
將返回託管在外部網站上的圖片的網址。問題是,這些圖像中的一些可能會被打破(404)。因此,例如:
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)
什麼我希望做的是更換破損圖像的URL字符串託管在我自己的網站一個「失蹤」的形象。因此,使用上面的例子中,與3.JPG和5.JPG被打破,我想會返回類似這樣:
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"
有沒有辦法解決這個問題的簡單方法?非常感謝提前。
我很欣賞這個輸入。不幸的是,這次我需要在服務器端完成所有這些工作,但是將來會考慮到這一點。 – btw 2009-12-18 20:39:36
感謝一個很好的客戶端修復羅馬。將這個添加到工具箱,謝謝;) – 2009-12-21 11:24:45
謝謝,漂亮的黑客 – Emmanuel 2012-12-18 16:56:39