0

我有更新属性的问题。我尝试通过 cron 更新。

调度程序.rb

every 3.minutes do
  runner "update_from_feed_continuously(feed_url)"
end

feed_entry.rb

class FeedEntry < ActiveRecord::Base
  attr_accessible :guid, :name, :url, :feed_url
  after_create { |feed| FeedEntry.update_from_feed(feed.feed_url) }
  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)
    feed = Feedzirra::Feed.update(feed)
    add_entries(feed.new_entries) if feed.updated?
  end

  private
  def self.add_entries(entries)
    entries.each do |entry|
      unless exists? :guid => entry.id
        create!(
          :name => entry.title, 
          :url => entry.url, 
          :guid => entry.id
        )
      end
    end
  end
end

每当我使用 gem feedzirra 和 gem

Loading development environment (Rails 3.2.13)
1.9.3p392 :001 > FeedEntry.update_from_feed_continuously(feed_url)
NameError: undefined local variable or method `feed_url' for main:Object
from (irb):1
from /Users/ipatov/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /Users/ipatov/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /Users/ipatov/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

1.9.3p392:002 >

我正在尝试实施 railscast http://railscasts.com/episodes/168-feed-parsing。最初我尝试通过控制台加载 feed_url,然后通过 cron 更新

4

0 回答 0