2017-11-09 4 views
0

レスポンスヘッダーのContent-Typeを 'application/json'に変更しようとしています。多くの方法を試しましたが、カールにはまだ「テキスト/プレーン」が含まれています。レスポンスヘッダーがContent-Type application/jsonを返さない

def my_action 
    file = File.read("#{Rails.root}/public/my_json") 
    json = JSON.parse(file) 

    # response.set_header('Content-Type', 'application/json') 
    # response.headers['Content-Type'] = 'application/json' 
    # render :text => json, :content_type => 'application/json' 
    # render :json => json, :content_type => 'application/json' 
    # render json: json, content_type: 'application/json' 

    render text: json, content_type: 'application/json' 
    end 

カール応答が

HTTP/1.1 200 OK Last-Modified: Thu, 09 Nov 2017 14:39:01 GMT Content-Type: text/plain Content-Length: 181 Server: WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13) Date: Thu, 09 Nov 2017 15:04:45 GMT Connection: Keep-Alive

Railsの5.0.6 ルビー2.2.2

任意のアイデアですか?

答えて

0

問題を解明しました。ルートは静的ファイルと同じ名前で、静的ファイル 'my_json'はルート 'my_json'よりも優先されます。

get 'my_json', to: 'files#my_action' 

text/plain代わりにapplication/jsonとしてレスポンスヘッダをもたらしました。

関連する問題