使用Axlsx-Rails Gem导出极其简单的Excel时出错

时间:2016-05-30 14:55:31

标签: ruby-on-rails ruby excel rubygems axlsx

我尝试使用Axlsx-Rails gem导出一个带有客户列表的简单Excel:

  # 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

模板路径为views/customers/customers.xlsx.axlsx,错误为Missing template customers/customers

错误在哪里?

1 个答案:

答案 0 :(得分:1)

我通过替换它来解决这个问题:

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

用这个:

render xlsx: "customers.xlsx"