別のWebサイトをスクレイプし、データを使用してRSSフィードをレンダリングするRuby/Railsアプリを開発しています。
このアプリはHerokuに基づいて構築されているため、ファイルシステムにダンプしてアセットとして提供するのではなく、コントローラーを介してRSSフィードを生成しています。
ただし、render :content_type
ハッシュを設定しても効果はありません。応答のコンテンツタイプはそのままtext/plain
です。
news
FeedControllerのアクション
def news
do_scrape
@posts = UbuEntry.all(:order => "created_at DESC", :limit => 400)
render :layout => false, :content_type => Mime::RSS
end
UbuWebRSS::Application.routes.draw do
root :to => 'index#index'
scope :format => true, :constraints => { :format => 'rss' } do
get 'feed/news' => 'feed#news'
end
end
ここでライブの結果を見ることができます:
http://www.ubuwebrss.com/feed/news.rss
そして完全なソースコード:
https://github.com/freen/ubuwebrss/
私はGoogleとStackOverflowを見回しましたが、何が間違っているのかはっきりしていません。
任意のヒント?ありがとう!
ご参考までに:
ビュースクリプト:/app/views/feed/news.rss.builder:
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title "UbuWeb"
xml.description "UbuWeb is a completely independent resource dedicated to all strains of the avant-garde, ethnopoetics, and outsider arts."
xml.link 'http://www.ubu.com'
for post in @posts
xml.item do
xml.title post.title
description = post.description.to_s
unless description.empty?
# Manually add description for custom HTML sanitizing
description = @sanitizer_basic.clean(description)
xml << " " * 6
xml << "<description><![CDATA[" + description + "]]></description>\n"
end
xml.pubDate post.created_at.to_s(:rfc822)
xml.link post.href
xml.guid post.href
end
end
end
end