Dan*_* B. 3 rss heroku scraper mime-types ruby-on-rails-3
我正在开发一个 Ruby/Rails 应用程序,它可以抓取另一个网站并使用数据呈现 RSS 提要。
因为这个应用程序是在 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
Run Code Online (Sandbox Code Playgroud)
完整路线.rb
UbuWebRSS::Application.routes.draw do
root :to => 'index#index'
scope :format => true, :constraints => { :format => 'rss' } do
get 'feed/news' => 'feed#news'
end
end
Run Code Online (Sandbox Code Playgroud)
您可以在此处查看实时结果:
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
Run Code Online (Sandbox Code Playgroud)
似乎它在这里返回了正确的内容类型(带有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
Run Code Online (Sandbox Code Playgroud)
可能是 Chrome 中的错误,而不是您的应用程序中的错误。
| 归档时间: |
|
| 查看次数: |
1301 次 |
| 最近记录: |