SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard jag5311's Avatar
    Join Date
    Jan 2003
    Location
    Somewhere in Indiana
    Posts
    3,082
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pull in an XML feed with Ruby on Rails

    Sorry if this is such a newbie question, but I am looking to pull in an RSS feed and display it via Ruby on Rails.

    Can someone point me to a tutorial on how I can accomplish this.

    thanks,
    Bryan

  2. #2
    SitePoint Wizard silver trophy Bleys's Avatar
    Join Date
    Feb 2003
    Location
    RI-USA
    Posts
    5,620
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You may be interested in Scott Raymond's RSS and Atom RXML Templates.

    Also, the FeedTools libarary may be very useful to you.
    Josh is an anomaly
    rails & work & twitter

    Organization is the
    death of creativity.

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use FeedTools (that Bleys linked to) to import and publish feeds. It makes things really easy (though publishing with .rxml Builder templates is also really easy, it's where importing feeds that makes FeedTools really valuable imo).

    For importing feeds via URL:
    Code:
    require 'open-uri'
    open @feed_url
    feed = FeedTools::Feed.open(params[:feed_url])
    
    your_model_params['url'] = item.link
    your_model_params['title'] = item.title
    your_model_params['description'] = item.description
    
    # Build tags from the categories, if any.
    tags = item.categories.collect {|c| c.term}.join(' ')
    
    your_model = YourModel.new(your_model_params)
    your_modeltag_with(tags)
    if your_model.save
      # do stuff
    end
    # do stuff
    If you need to import from an uploaded file:
    Code:
    feed = FeedTools::Feed.new
    feed.feed_data = params[:feed_file].read
    
    # do the same stuff as before
    Displaying your own feed is just a matter of setting up a FeedTools::Feed object in your controller and then doing this in your view (.rxml template):

    Code:
    @feed.build_xml(@flavor, @version, xml)
    Check out the FeedTools RDocs for more on the API.

  4. #4
    SitePoint Wizard silver trophy Bleys's Avatar
    Join Date
    Feb 2003
    Location
    RI-USA
    Posts
    5,620
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Chu, good to see you back! Long time, no see.
    Josh is an anomaly
    rails & work & twitter

    Organization is the
    death of creativity.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •