我尝试使用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
错误在哪里?
答案 0 :(得分:1)
我通过替换它来解决这个问题:
respond_to do |format|
render xlsx: 'customers.xlsx.axlsx'
end
用这个:
render xlsx: "customers.xlsx"