Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Rails-呈现:内容类型无效_Ruby On Rails 3_Heroku_Rss_Mime Types_Scraper - Fatal编程技术网

Ruby on rails 3 Rails-呈现:内容类型无效

Ruby on rails 3 Rails-呈现:内容类型无效,ruby-on-rails-3,heroku,rss,mime-types,scraper,Ruby On Rails 3,Heroku,Rss,Mime Types,Scraper,我正在开发一个Ruby/Rails应用程序,它可以抓取另一个网站并用数据呈现RSS提要 因为这个应用程序是基于Heroku构建的,所以我通过一个控制器生成RSS提要,而不是将其转储到文件系统并将其作为一项资产 但是,当我设置render:content\u typehash时,没有效果。响应的内容类型仍然是text/plain 新闻关于 满满的 您可以在此处看到实时结果: 以及完整的源代码: 我环顾了谷歌和StackOverflow,但不清楚我做错了什么 有什么建议吗?谢谢 供参考: 查看脚

我正在开发一个Ruby/Rails应用程序,它可以抓取另一个网站并用数据呈现RSS提要

因为这个应用程序是基于Heroku构建的,所以我通过一个控制器生成RSS提要,而不是将其转储到文件系统并将其作为一项资产

但是,当我设置
render:content\u type
hash时,没有效果。响应的内容类型仍然是
text/plain

新闻
关于

满满的

您可以在此处看到实时结果:

以及完整的源代码:

我环顾了谷歌和StackOverflow,但不清楚我做错了什么

有什么建议吗?谢谢

供参考:

查看脚本::

xml.instruction!:xml,:version=>“1.0”
xml.rss:version=>“2.0”do
xml.channeldo
xml.title“UbuWeb”
描述“UbuWeb是一个完全独立的资源,致力于所有先锋派、人种学和外来艺术的流派。”
xml.link'http://www.ubu.com'
对于@posts中的post
xml.item-do
xml.title post.title
description=post.description.to_s
除非是空的?
#手动添加自定义HTML清理的说明
description=@sanitizer\u basic.clean(description)

xml似乎返回了正确的内容类型(使用
curl-i
):


可能是Chrome中的错误,而不是你的应用程序。

请解释你是如何验证它发送回的是纯文本,而不是应用程序/rss+xml。没错。chrome网络面板始终(错误地)将内容类型指示为“文本/普通”。谢谢这对我很有帮助,我尝试使用content_type、mime_type,并在我的初始值设定项中直接注册这些格式的默认mime类型-什么都没有。原来问题一直是铬。
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
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
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