2009-07-02 91 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