我有两个模型 Company 和 News 如何让新闻每 30 分钟下载一次?我已经尝试过 gem '无论何时',没有任何反应
class Company < ActiveRecord::Base
after_save :load_news
def load_news
last_entry = self.news.last
if last_entry.nil?
feed = Feedzirra::Feed.fetch_and_parse(self.url)
else
feed = Feedzirra::Feed.fetch_and_parse(self.url,
:if_modified_since => last_entry.published_at.to_time)
end
Company.add_entries(feed.entries, self.id)
end
def self.update_all_feeds(urls)
Feedzirra::Feed.fetch_and_parse(urls,
:on_success => lambda { |url, feed|
rss = Comapny.select("companies.id").where(:url => url).first
Company.add_entries(feed.entries, rss.id)
}
)
end
end
class News < ActiveRecord::Base
attr_accessible :content, :guid, :name, :published_at, :summary, :url, :company_id
end