0
我有以下存儲在rake任務中。基本上,我需要從1更新「發佈」屬性爲0;如果從URL響應代碼是不是200。當我運行該拿我得到: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
完美的作品!謝謝! – Yogzzz