私は次のものをレーキタスクに保存しています。基本的に、URLからの応答コードが200でない場合は、「published」属性を1から0に更新する必要があります。このテイクを実行すると、次のようになります。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