Alejandro Araujo
Alejandro Araujo

Reputation: 149

Error exporting an extremely simple Excel with Axlsx-Rails Gem

I'm trying to export a simple Excel with a customers list using Axlsx-Rails gem:

  # Customers Controller
  def download
      @customers = Customer.all
      respond_to do |format|
        render xlsx: 'customers.xlsx.axlsx'
        # render xlsx: 'customers' TRYED BOTH
      end
  end

  # Template
  wb = xlsx_package.workbook
  wb.add_worksheet(name: "Download") do |sheet|
    @customers.each do |customer|
      sheet.add_row [customer.name, customer.email, customer.phone]
    end
  end

The template path is views/customers/customers.xlsx.axlsx and the error is Missing template customers/customers

Where is the error?

Upvotes: 0

Views: 1103

Answers (1)

Alejandro Araujo
Alejandro Araujo

Reputation: 149

I fixed this by replacing this:

respond_to do |format|
   render xlsx: 'customers.xlsx.axlsx'
end

with this:

render xlsx: "customers.xlsx"

Upvotes: 1

Related Questions