1

動的に生成された json データが表示されるのではなく、ブラウザによってダウンロードされるように応答を設定するにはどうすればよいですか?

アクティブ管理者を使用しています

  member_action :download, :method => :get do
    application = Application.find(params[:id])
    respond_to do |format|
      format.json { render json: application.to_json( include: { categories: { include: { my_cases: { include: [{ questions: { include: :answers } }, :keys ] } } } } ) }
    end
  end
4

1 に答える 1

7

使用send_data方法:

respond_to do |format|
  format.json { send_data application.to_json( include: { categories: { include: { my_cases: { include: [{ questions: { include: :answers } }, :keys ] } } } } ), type: :json, disposition: "attachment" }
end
于 2013-03-16T06:02:43.520 に答える