如何设置响应以便浏览器下载动态生成的json数据,而不显示?
我正在使用Active Admin
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
答案 0 :(得分:6)
使用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