在Ruby中解析RSS Feed

时间:2014-04-03 04:01:11

标签: ruby-on-rails ruby mongodb parsing mongoid

所以我是Ruby on Rails的新手,但我基本上是尝试使用SimpleRSS解析一个feed,然后存储各种值并显示它。我正在使用MongoDB / mongoid gem作为数据库。

我可以解析Feed,但是没有一个值得到正确存储。

class FeedEntry

  include Mongoid::Document
  require 'rubygems'
  require 'simple-rss'
  require 'open-uri'

  field :name, type: String
  field :summary, type: String
  field :url, type: String
  field :published_at, type: DateTime
  field :guid, type: Integer

  def self.rssFeeder(feed_url)
    feed = SimpleRSS.parse open(feed_url)
    feed.items.each do |entry|
      unless FeedEntry.where(guid: entry.id).exists?
        FeedEntry.create!(
          name: entry.title,
          summary: entry.summary,
          url: entry.link,
          published_at: entry.pubDate,
          guid: entry.id
        ) 
      end
    end
  end

end

我可以得到FeedEntry.count为76,但存储的所有值都是nil

有没有人看到明显的错误?

0 个答案:

没有答案