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 回答