I’m currently working on a large surveying application which is currently in production on Heroku (Cedar, 4 web dynos, Crane PostgreSQL database). Due to time constraints, I have a Survey model, with the questions exposed through attr_accessible. I am looking to export the days results, which is generally 5000+ rows of data, with about 45 columns.
When I export the day’s surveys (Survey.where("created_at >= ?", Time.now.beginning_of_day)), using a combination of this and this, it prompts for download, downloads, but when I open it, I only have about 2/3 of the data. Sometimes it cuts off about midway through a row.
It seems like I’m hitting some sort of memory issue, or an issue sending everything to the Excel/CSV properly. I’m convinced it’s because of data size, but I can’t control that, I’m just trying to find the issue. Any ideas on how I can try to resolve this? It’s pretty debilitating.
Here’s the code in the survey model which handles the CSV/Excel writing:
def self.to_csv(options = {})
CSV.generate do |csv|
csv << column_names
all.find_each do |survey|
csv << survey.attributes.values_at(*column_names)
end
end
end
Currently on the controller I format everything in a index.xls.erb.
Thanks for any help you can provide.
I resolved this issue! After a bit of poking around, I switched from using a HTML formatted view/xls file to just doing a barebones CSV , formatted in a view, as referenced in this answer. This worked perfectly. Thanks for the troubleshooting ideas everyone!