setting the filename for a downloaded file in a rails application

前端 未结 3 1338
南方客
南方客 2020-12-10 12:52

I have a controller action that allows a user to download a file with an extension of .ppt . It\'s not really a powerpoint binary, just an xml-ish format that powerpoint can

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 13:36

    A possible example:

    def show
        @item = Item.find(params[:id])
        respond_to do |format|
            format.html # show.html.erb
            format.ppt {
                response.headers['Content-Disposition'] = "attachment; filename=\"#{@item.filename}.ppt\""
            } # show.ppt.erb
            format.xml  { render :xml => @item }
        end
    end
    

提交回复
热议问题