我想查看旧网站上是否存在几个网址,并收集返回404的网址。
@paintings = Painting.find(:all)
@paintings.each do |painting|
open("http://www.mydomain.com/" + painting.user.username.downcase + "/" + painting.permalink)
rescue OpenURI::HTTPError
@failure += painting.permalink
else
@success += painting.permalink
end
end
嗯,我无法通过救援方法来获取错误
syntax error, unexpected kRESCUE, expecting kEND
rescue OpenURI::HTTPError
有什么想法吗?
答案 0 :(得分:20)
您似乎在开放之前忘记了begin
:
begin
open("http://www.mydomain.com/" + painting.user.username.downcase + "/" + painting.permalink)
rescue OpenURI::HTTPError
@failure += painting.permalink
else
@success += painting.permalink
end