0
我使用Ruby的RSS類在Sinatra應用程序中生成RSS源。該Feed對每個用戶都是唯一的。如何將Feed連接到URL以便用戶可以使用其RSS閱讀器進行訂閱,並自動接收新的Feed更新?如何將rss feed鏈接到url
我使用Ruby的RSS類在Sinatra應用程序中生成RSS源。該Feed對每個用戶都是唯一的。如何將Feed連接到URL以便用戶可以使用其RSS閱讀器進行訂閱,並自動接收新的Feed更新?如何將rss feed鏈接到url
無恥地從http://recipes.sinatrarb.com/p/views/rss_feed_with_builder
被盜安裝或添加Builder
寶石:
# add to Gemfile and run `bundle`...
gem 'builder'
# ... or install system-wide
$ gem install builder
添加合適的路由(S)到您的應用程序/控制器:
# in app.rb
get '/rss' do
@posts = # ... find posts
builder :rss
end
創建視圖顯示RSS種子:
# in views/rss.builder
xml.instruct! :xml, :version => '1.0'
xml.rss :version => "2.0" do
xml.channel do
xml.title "Cool Website News"
xml.description "The latest news from the coolest website on the net!"
xml.link "http://my-cool-website-dot.com"
@posts.each do |post|
xml.item do
xml.title post.title
xml.link "http://my-cool-website-dot.com/posts/#{post.id}"
xml.description post.body
xml.pubDate Time.parse(post.created_at.to_s).rfc822()
xml.guid "http://my-cool-website-dot.com/posts/#{post.id}"
end
end
end
end
進一步閱讀: