-2

Andrew

I am new for ROR Developer. i have one table to insert car images. but, that images are remote url. I have to insert 60,000 rows. i got like this "error execution terminated". Can you help how do i fix this issue?

Here My Code:

namespace :db do
  task :load_photo  => :environment do
    require 'rubygems'
    require 'open-uri'
    require 'net/http'
    require 'paperclip'
    Website.find_in_batches(:conditions=>["image_url is not null"]) do |websites|
      websites.each do |website|
        begin
          url = URI.parse(website.image_url)
          Net::HTTP.start(url.host, url.port) do |http|
            if http.head(url.request_uri).code == "200"
              Car.update_attribute(:photo,open(url))
            end
          end
        rescue Exception => e
        end
      end
    end
  end 
end
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
Anandh L.v
  • 95
  • 1
  • 2
  • 11
  • Please see [Why is it bad style to `rescue Exception => e` in Ruby?](http://stackoverflow.com/questions/10048173/why-is-it-bad-style-to-rescue-exception-e-in-ruby/10048406#10048406) – Andrew Marshall Apr 12 '12 at 08:17

1 Answers1

1

I would suggest you to not rescue all Exception like you did with :

rescue Exception => e
end

then you will have (and be able to give us) more information about the error generated. Notice that it is a good practice to rescue only exception you want.

Adrien Coquio
  • 4,870
  • 2
  • 24
  • 37