2009-07-02 6 views
4

Je voudrais vérifier si la EXST de quelques URL sur mon ancien site Web et recueillir des URLS qui retourne 404.rubis Ouvrir l'URL et le sauvetage

@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 

Hmmm, je ne peux pas obtenir cette méthode de sauvetage pour ramasser l'erreur

syntax error, unexpected kRESCUE, expecting kEND 
     rescue OpenURI::HTTPError 

Des idées?

Répondre

19

On dirait que vous avez oublié le begin avant l'ouverture:

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 :) Merci. – atmorell

Questions connexes