articles.each do |article| item = maker.items.new_item item.link = "http://www.***.com/archives/#{article.id}" item.title = article.title item.date = article.post_date item.description = "" end end send_data feed.to_s, :type => "application/rss+xml", :disposition => "inline" end
方法B: Rails Controller->Action 代码:
复制代码 代码如下: #Post_controller::feed def feed @posts=Post.find :all,:limit=>”id desc” end
erb模板:
xml.instruct! xml.rss(”version”=>”2.0″, “xmlns:dc”=>”http://purl.org/dc/elements/1.1/”) do xml.channel do xml.title “renlu.xu "s blog” xml.link(url_for(:action=>”start”,:only_path=>false)) xml.description “My life My love” xml.language “zh_CN” xml.ttl 60
for event in @posts do xml.item do xml.title(event.title) xml.description(event.body) xml.pubDate(event.created_at.to_s(:rfc822)) xml.guid(event.id) xml.link(”http://…..#{event.id}”) end end end end