我正在循环访问外部网站托管的图像的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