3

別のWebサイトをスクレイプし、データを使用してRSSフィードをレンダリングするRuby/Railsアプリを開発しています。

このアプリはHerokuに基づいて構築されているため、ファイルシステムにダンプしてアセットとして提供するのではなく、コントローラーを介してRSSフィードを生成しています。

ただし、render :content_typeハッシュを設定しても効果はありません。応答のコンテンツタイプはそのままtext/plainです。

newsFeedControllerのアクション

def news
  do_scrape
  @posts = UbuEntry.all(:order => "created_at DESC", :limit => 400)
  render :layout => false, :content_type => Mime::RSS
end

フルroutes.rb

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
4

1 に答える 1

5

ここで正しいコンテンツタイプを返しているようです( with curl -i <url>):

HTTP/1.1 200 OK 
Server: nginx
Date: Mon, 04 Feb 2013 00:10:05 GMT
Content-Type: application/rss+xml; charset=utf-8
Content-Length: 121890
Connection: keep-alive
X-Ua-Compatible: IE=Edge,chrome=1
Etag: "74ebbfe3182fef13d8a737580453f688"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 9377e469ffad158b2480a3f6b2f2866c
X-Runtime: 0.748709
X-Rack-Cache: miss

アプリではなく Chrome のバグである可能性があります。

于 2013-02-04T00:10:47.493 に答える