Skip to content

Commit

Permalink
rescue exception when converting post, upgrade to rails 2.3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
ehutzelman committed Aug 11, 2010
1 parent 42dc252 commit adca5e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions app/models/post.rb
Expand Up @@ -4,29 +4,30 @@ class Post
attr_accessor :title, :author, :description, :url, :created_at

RSS_URL = "http://rss.groups.yahoo.com/group/Houston-RoR/rss"

def self.all
posts = []
REXML::Document.new(messages_xml).elements.to_a("//item").each do |element|
posts << create_post_from_xml(element)
end

posts
end

def self.messages_xml
URI.parse(RSS_URL).read
end

def self.create_post_from_xml(xml)
post = Post.new
post.title = xml.elements['title'].text
post.description = xml.elements['description'].text rescue nil
post.created_at = Time.parse(xml.elements['pubDate'].text)
post.author = xml.elements['dc:creator'].text
post.url = xml.elements['link'].text

post
rescue:
post
end

end
2 changes: 1 addition & 1 deletion config/environment.rb
@@ -1,7 +1,7 @@
# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Expand Down

0 comments on commit adca5e7

Please sign in to comment.