Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## feed.rb
- class Feed < ActiveRecord::Base
- has_many :items
- after_create :update_title
- after_create :create_items
- def create_items
- source = self.site_url
- content = ""
- open(source) do |s|
- content = s.read
- end
- rss = RSS::Parser.parse(content, false)
- for item in rss.items
- Item.create(:title => item.title, :item_url => item.link, :description => item.description, :feed_id => self.id)
- end
- end
- def update_title
- source = self.site_url
- content = ""
- open(source) do |s|
- content = s.read
- end
- rss = RSS::Parser.parse(content, false)
- Feed.update(self.id, { :title => rss.channel.title, :description => rss.channel.description })
- end
- end
Add Comment
Please, Sign In to add comment