开发者

Building a news feed for my Rails site. Any pointers?

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开发者_C百科 now), should that be sufficient, or is NoSQL the way to go?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜