I am trying to save a rake task into my database to I can display the content in my view.
Here's the task:
desc "Fetch Digital Trends"
task :fetch_trends => :environment do
require 'nokogiri'
require 'httparty'
url = "http://www.digitaltrends.com/computing/"
doc = Nokogiri::HTML(open(url))
doc.css(".post").each do |item|
title = item.at_css(".content h3").text
link = item.at_css(".content h3 a")[:href]
puts "#{title} - #{link}"
end
end
It is possible to make this task run every hour to update the content?