Ruby Open URL and save

I would like to check if there are several exst URLs 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 

Hmmmm, I can't get this rescue method to get an error

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

Any ideas?

+4
source share
1 answer

Looks like you forgot begin before opening:

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

All Articles