From c46cab6a6f5b1f7e8b790bc8e2c10faf7995affd Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Thu, 28 Jul 2016 23:30:49 -0400 Subject: [PATCH] Update customers_controller.rb --- app/controllers/customers_controller.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 133d882..963edcd 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -20,7 +20,7 @@ class CustomersController < ApplicationController def index if params[:search] @customers = Customer.search(params[:search]).paginate(:page => params[:page]) - if @customers.count = 1 + if only_one_non_zero?(@customers) redirect_to @customers.first end else @@ -88,5 +88,18 @@ class CustomersController < ApplicationController render_404 end end + + private + + def only_one_non_zero?( array ) + found_non_zero = false + array.each do |val| + if val!=0 + return false if found_non_zero + found_non_zero = true + end + end + found_non_zero + end end