0

I have the following stored in a rake task. Basically I need it update the "published" attribute to 0 from 1 if the response code from the url is not 200. When I run this take I get: undefined method 'request_uri' for #<URI::Generic:0x00000102136408 URL:url>

desc "Problem products"
task :update_broken_links => :environment do
  require 'net/http'

  Product.find(:all, :conditions =>["published = ? AND feed_id = ?", '1', 820]).each do |product|
    url = product.url 
    uri = URI('url')
    response = Net::HTTP.get_response(uri)
    x = response.code.to_i    

    if x != 200
      published = '0'
    else
      published = product.published
    end


    product.update_attribute(:publsihed, publsihed) 

  end
end
Hauleth
  • 22,873
  • 4
  • 61
  • 112
Yogzzz
  • 2,735
  • 5
  • 36
  • 56

1 Answers1

0

Where you have uri = URI('url') you need to change it to uri = URI(url). Your current code is trying to convert the string 'uri' into a URI instead of using the contents of the uri variable.

You'll also run into a problem near the end at product.update_attribute(:publsihed, publsihed) once you get there. You've got a typo: 'publsihed' instead of 'published'.

Emily
  • 17,813
  • 3
  • 43
  • 47