2016-03-21 101 views
1

我需要爲Apple通用鏈接發送具有特定內容類型(application/pkcs7-mime)的文件。 我使用rails的send_file函數,並添加:type作爲參數, 但類型始終爲text/plain使用send_file設置內容類型

這裏是我的控制器:

class AppleController < ApplicationController 
    def download_app_site_association 
    send_file "#{Rails.root}/public/apple-app-site-association", {:filename => "apple-app-site-association", :type => "application/pkcs7-mime" , :x_sendfile => true} 
    end 
end 

我也嘗試添加這樣的:

send_file "#{Rails.root}/public/apple-app-site-association", :filename => "apple-app-site-association", :type => "application/pkcs7-mime" , :x_sendfile => true 

和手動設置它像這樣:

response.headers["Content-type"] = "application/pkcs7-mime" 
send_file "#{Rails.root}/public/apple-app-site-association", :filename => "apple-app-site-association", :x_sendfile => true 

誰能給我解釋一下爲什麼這不起作用?

回答

1

我找到了解決方案。 的問題是,當我試圖讓mywebsite.com/apple-app-site-association,路由器首先搜索文件在#{Rails.root}/public/,然後在routes.rb

搜索路徑作爲我的文件,我的路線有相同的名稱,apple_controller從未達到。

所以我只是改變了文件名。