只是一个快速的问题。在观看 RailsCasts ep #168 并遇到以下代码后:
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(blah, blah) 方法?它会在我的 Feed 控制器中,还是在视图中(即索引、显示等)
任何帮助深表感谢。这个问题困扰了我好久...