我正在尝试为我的新闻帖子创建一个 RSS 提要,我用谷歌搜索它并想出了以下代码:
def feed
@posts = News.all(:conditions => "#{Settings.show} = 1", :select => "id, title, heading, content, date_posted", :order => "date_posted DESC")
respond_to do |format|
format.rss { render :layout => false }
end
end
然后在一个名为“feed.rss.builder”的文件中,我有这个:
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title "Your Blog Title"
xml.description "A blog about software and chocolate"
xml.link posts_url
for post in @posts
xml.item do
xml.title post.title
xml.description post.content
xml.pubDate post.date_posted.to_s(:rfc822)
xml.link post_url(post)
xml.guid post_url(post)
end
end
end
end
我已将它添加到我的路由文件match "/news/feed" => "aboutus#feed"
中,但是当我转到该页面时,什么都没有呈现..