Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.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 Rails呈现忽略内容类型散列值_Ruby On Rails_Ruby On Rails 3.1 - Fatal编程技术网

Ruby on rails Rails呈现忽略内容类型散列值

Ruby on rails Rails呈现忽略内容类型散列值,ruby-on-rails,ruby-on-rails-3.1,Ruby On Rails,Ruby On Rails 3.1,我在我的一个资源上有一个下载附件文件的操作。代码非常简单 def download content_type = @book.attachments[params[:name]]['content_type'] data = @book.read_attachment(params[:name]) render :text => data, :content_type => content_type end 然而,rails完全忽略了这一点,不管发生

我在我的一个资源上有一个下载附件文件的操作。代码非常简单

  def download
    content_type = @book.attachments[params[:name]]['content_type']
    data = @book.read_attachment(params[:name])
    render :text => data, :content_type => content_type
  end
然而,rails完全忽略了这一点,不管发生什么情况,每次都将响应设置为text/html。我甚至尝试使用response.header['Content-Type']将其设置为无效


如果有必要的话,我使用的是rails 3.1。

尝试改用send\u data

send_data data, :type => content_type

这导致它可以直接下载(而不是在浏览器页面中打开),但类型仍然是text/htmlOk,所以我认为它可以工作,一些带有Chrome和“未修改”的东西导致它显示旧的内容类型。更改内容查询地址似乎有帮助。