2009-07-02 89 views
4

我想,如果幾URL的EXST檢查我的舊網站收集的網址返回404紅寶石打開URL和救援

@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 

任何想法?

回答

19

看起來你已經忘記了begin開放之前:

begin 
    open("http://www.mydomain.com/" + painting.user.username.downcase + "/" + painting.permalink) 
rescue OpenURI::HTTPError 
    @failure += painting.permalink 
else 
    @success += painting.permalink 
end 
+0

Perfetct :)謝謝。 – atmorell 2009-07-02 11:32:08