Rails呈现忽略content_type哈希值

时间:2011-09-18 23:22:43

标签: 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完全忽略了这一点,并且每次都无论如何都设置对text / html的响应。我甚至尝试使用response.header ['Content-Type']设置它无效。

如果重要的话,我正在使用rails 3.1。

1 个答案:

答案 0 :(得分:2)

请尝试使用send_data。

send_data data, :type => content_type