0
只是一個簡單的問題。看着RailsCasts EP#168和整個下面的代碼來後:何時/從哪裏調用self.update_from_feed_continuously?
class FeedEntry < ActiveRecord::Base
def self.update_from_feed(feed_url)
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
end
def self.update_from_feed_continuously(feed_url, delay_interval = 15.minutes)
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
add_entries(feed.entries)
loop do
sleep delay_interval
feed = Feedzirra::Feed.update(feed)
add_entries(feed.new_entries) if feed.updated?
end
end
private
def self.add_entries(entries)
entries.each do |entry|
unless exists? :guid => entry.id
create!(
:name => entry.title,
:summary => entry.summary,
:url => entry.url,
:published_at => entry.published,
:guid => entry.id
)
end
end
end
end
我問自己,哪裏/當我應該調用的方法self.update_from_feed_continuously(等等,等等)?它會在我的飼料控制器,或視圖(即索引,顯示等..)
任何幫助,非常感謝。這個問題一直困擾着我一段時間...