2010-11-01 82 views
1

我想讓feedzirra在rails 3上運行,我嘗試了一些我在互聯網上找到的方法。Feedzirra in Rails 3

這是我的Gemfile:

source 'http://gems.github.com' 

gem 'loofah', '1.0.0.beta.1' 
group :after_initialize do 
    gem 'pauldix-feedzirra' 
end 

和我root.rb

Bundler.require :after_initialize 

已經出這個bundle.setup後,這是在我的模型代碼(movie.rb )

class Movie < ActiveRecord::Base 
    def self.import_from_feed 
    feed = Feedzirra::Feed.fetch_and_parse("url-to.xml") 
    add_entries(feed.entries) 
    end 

    private 

    def self.add_entries(entries) 
    entries.each do |entry| 
     unless exists? :guid => entry.id 
     create!(
      :title  => entry.title, 
      :synopsis  => entry.synopsis, 
      :cover  => entry.cover, 
      :duration  => entry.duration, 
      :channel  => entry.channel, 
      :imdb_rating => entry.imdb_rating, 
      :imdb_votes => entry.imdb_votes, 
      :imdb_id  => entry.imdb_votes 
     ) 
     end 
    end 
    end 
end 

我嘗試從控制檯運行import_from_feed功能,我不斷收到此錯誤:

>> Movie.import_from_feed 
NameError: uninitialized constant Movie::Feedzirra 
    from /Users/myname/Ruby/appname/app/models/movie.rb:3:in `import_from_feed' 
    from (irb):1 

有人可以幫我嗎?現在已經嘗試了很多年!

回答

6

兩件事情:

  1. 只需添加寶石,不在:after_initialize
  2. 使用feedzirra寶石,不要老pauldix-feedzirra之一。