如何更新属性

时间:2013-05-13 16:37:29

标签: ruby-on-rails whenever feedzirra

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

sheduler.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&gt;

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

更新

0 个答案:

没有答案