How to download a CSV file in Ruby on Rails?

前端 未结 3 1689
鱼传尺愫
鱼传尺愫 2021-02-02 12:34

In my InvoicesController I have this:

def index
  @invoices = current_user.invoices
  respond_to do |format|
    format.html
    format.xls
    form         


        
3条回答
  •  隐瞒了意图╮
    2021-02-02 13:22

    Try this

    format.csv do
      response.headers["Content-Type"] = "text/csv; charset=UTF-8; header=present"
      response.headers["Content-Disposition"] = "attachment; filename=invoices.csv"
    end
    

提交回复
热议问题