views:

32

answers:

1

I have a Rails site. I want to create a news feed.

Does anyone have any pointers/advice/caution with this?

What are some common schemas?

We're using ActiveRecord+MySQL (at least for now), should that be sufficient, or is NoSQL the way to go?

+2  A: 

Well, a feed is just a representation of your content in some format suitable for RSS readers.

1) Generate the feed using XML Builder.

Controller:

@articles = Post.find :all

respond_to do |format|
  format.html
  format.rss  { render :layout => false }
end

View (myfeed.rss.builder):

xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
  xml.channel do
    xml.title "My RSS feed"
    xml.link articles_url

    for art in @articles 
      xml.item do
        xml.title art.title
        xml.description art.annotation
        xml.pubDate art.created_at.to_s(:rfc822)
        xml.link article_url(post)
      end
    end
  end
end

2) Use the atom_feed helper in Rails. Check it here.

floatless
Thanks for the response. I'd say my main problem is not figuring out formatting, but the schema and other application code for automatically collecting information from various parts of the application into one single feed.
I'd also add that since we're not going to make an api or have this content outside of the site, I don't think it would make much sense to render xml that's just going to get parsed and serialized back into Ruby. Might as well just keep it as Ruby.