From 310f2f3d4624f4345794538b2f32c9a18ed4c381 Mon Sep 17 00:00:00 2001 From: Godwin Date: Mon, 18 Jul 2016 10:10:36 -0700 Subject: [PATCH] Fixed divide by zero error on stats page --- app/views/conferences/admin/_stats.html.haml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/conferences/admin/_stats.html.haml b/app/views/conferences/admin/_stats.html.haml index 1537de3..e0f9209 100644 --- a/app/views/conferences/admin/_stats.html.haml +++ b/app/views/conferences/admin/_stats.html.haml @@ -1,17 +1,17 @@ .details = data_set(:h4, 'articles.admin.stats.headings.registrations') do - = @registrations.size + = (@registration_count || 0).to_s = data_set(:h4, 'articles.admin.stats.headings.bikes') do - = "#{@bikes} (#{(@bikes / @registration_count) * 100.0}%)" + = (@registration_count || 0) > 0 ? "#{@bikes} (#{(@bikes / @registration_count) * 100.0}%)" : "0" = data_set(:h4, 'articles.admin.stats.headings.food.meat') do - = "#{@food[:meat]} (#{(@food[:meat] / @food[:all]) * 100.0}%)" + = (@food[:all] || 0) > 0 ? "#{@food[:meat]} (#{(@food[:meat] / @food[:all]) * 100.0}%)" : "0" = data_set(:h4, 'articles.admin.stats.headings.food.vegetarian') do - = "#{@food[:vegetarian]} (#{(@food[:vegetarian] / @food[:all]) * 100.0}%)" + = (@food[:all] || 0) > 0 ? "#{@food[:vegetarian]} (#{(@food[:vegetarian] / @food[:all]) * 100.0}%)" : "0" = data_set(:h4, 'articles.admin.stats.headings.food.vegan') do - = "#{@food[:vegan]} (#{(@food[:vegan] / @food[:all]) * 100.0}%)" + = (@food[:all] || 0) > 0 ? "#{@food[:vegan]} (#{(@food[:vegan] / @food[:all]) * 100.0}%)" : "0" = data_set(:h4, 'articles.admin.stats.headings.donation_count') do - = "#{@donation_count} (#{(@donation_count / @registration_count) * 100.0}%)" + = (@registration_count || 0) > 0 ? "#{@donation_count} (#{(@donation_count / @registration_count) * 100.0}%)" : "0" = data_set(:h4, 'articles.admin.stats.headings.donation_total') do - = "$#{@donations}" + = "$#{@donations || 0.00}" .actions = link_to (_'links.download.Excel'), administration_step_path(@this_conference.slug, :stats, :format => :xlsx), class: [:button, :download]