我在我的一个资源上有一个动作来下载附件文件。代码非常简单
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。
答案 0 :(得分:2)
请尝试使用send_data。
send_data data, :type => content_type