[英]Saving rake task in database to add in view
我正在嘗試將rake任務保存到我的數據庫中,以便在我的視圖中顯示內容。
這是任務:
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
可以每小時運行一次此任務來更新內容嗎?
你可以使用cron。 看看https://github.com/javan/whenever(Ruby中的 Cron作業)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.