使用Axlsx-Rails Gem导出极其简单的Excel时出错
我想用一个客户列表使用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
模板path是views/customers/customers.xlsx.axlsx
,错误是Missing template customers/customers
错误在哪里?
我解决这个问题,取而代之:
respond_to do |format| render xlsx: 'customers.xlsx.axlsx' end
有了这个:
render xlsx: "customers.xlsx"