So I am using this gem axlsx_rails
for exporting some data in excel file. But sometimes I get error like forbidden character as name or name exceed 31 character size. I don't understand how to handle these errors. All I want is to render index again if such error occurs and show a flash message. My current code is below
Class CustomersController
def index
@customers = Customer.all
respond_to do |format|
format.html # index.html.erb
format.xls
format.xlsx
end
end
end
and index.xlsx.axlsx
wb = xlsx_package.workbook
@customers = Customer.all
@customers.each do |customer|
wb.add_worksheet(name: customer.name) do |sheet|
sheet.add_row ["Name", ...... ]
.
.
.
end