Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby Open URL and rescue

I would like to check if a few URL's exst on my old website and collect URLS that returns 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

Hmmm I can't get that rescue method to pick up the error

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

Any ideas?

like image 386
atmorell Avatar asked Dec 01 '22 12:12

atmorell


1 Answers

Looks like you've forgotten the begin prior to the open:

 begin
  open("http://www.mydomain.com/" + painting.user.username.downcase + "/" + painting.permalink)
 rescue OpenURI::HTTPError
   @failure += painting.permalink
 else
   @success += painting.permalink
 end
like image 55
Shadwell Avatar answered Dec 05 '22 01:12

Shadwell