From a324d804b9f56d701067b593057e4fdaf760ce13 Mon Sep 17 00:00:00 2001 From: cmatiello Date: Wed, 20 Feb 2019 15:36:58 -0300 Subject: [PATCH] Fix export csv error when there are no stories in the projects (#515) --- config/initializers/csv_renderer.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/initializers/csv_renderer.rb b/config/initializers/csv_renderer.rb index f96102616..9be2a4fc7 100644 --- a/config/initializers/csv_renderer.rb +++ b/config/initializers/csv_renderer.rb @@ -2,10 +2,10 @@ # assumption that that is what we get passed. ActionController::Renderers.add :csv do |stories, options| number_of_extra_columns = {} - number_of_extra_columns[:notes] = stories.map{ |story| story.notes.length }.max - number_of_extra_columns[:documents] = stories.map{ |story| story.documents.length }.max - number_of_extra_columns[:tasks] = stories.map{ |story| story.tasks.length }.max - + number_of_extra_columns[:notes] = stories.map{ |story| story.notes.length }.max || 0 + number_of_extra_columns[:documents] = stories.map{ |story| story.documents.length }.max || 0 + number_of_extra_columns[:tasks] = stories.map{ |story| story.tasks.length }.max || 0 + filename = options[:filename] || 'export.csv' headers = Story.csv_headers.dup headers.concat(extra_headers(number_of_extra_columns))