From 983811af97e98655cc436eb5c3cfa33fd76d677c Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 28 Mar 2020 20:08:44 -0400 Subject: [PATCH] Added comments to clearify methods --- app/controllers/vehicles_controller.rb | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb index 046a366..e7ffbfd 100644 --- a/app/controllers/vehicles_controller.rb +++ b/app/controllers/vehicles_controller.rb @@ -11,11 +11,11 @@ # This controller class will handle map management class VehiclesController < ApplicationController unloadable - + include AuthHelper - + before_filter :require_user - + # display a list of all vehicles def index if params[:customer_id] @@ -25,7 +25,8 @@ class VehiclesController < ApplicationController render_404 end end - + + # search for a vehicle by vin if params[:search] @vehicles = Vehicle.search(params[:search]).paginate(:page => params[:page]) if only_one_non_zero?(@vehicles) @@ -47,11 +48,11 @@ class VehiclesController < ApplicationController flash[:notice] = "New Vehicle Created" redirect_to @vehicle else - flash[:error] = @vehicle.errors.full_messages.to_sentence + flash[:error] = @vehicle.errors.full_messages.to_sentence redirect_to Vehicle.find_by_vin @vehicle.vin end end - + # display a specific vehicle def show begin @@ -61,7 +62,7 @@ class VehiclesController < ApplicationController render_404 end end - + # return an HTML form for editing a vehicle def edit begin @@ -71,11 +72,11 @@ class VehiclesController < ApplicationController render_404 end end - + # update a specific vehicle def update @customer = params[:customer] - begin + begin @vehicle = Vehicle.find_by_id(params[:id]) if @vehicle.update_attributes(params[:vehicle]) flash[:notice] = "Vehicle updated" @@ -88,7 +89,7 @@ class VehiclesController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end - end + end # delete a specific vehicle def destroy @@ -100,9 +101,11 @@ class VehiclesController < ApplicationController render_404 end end - + private - + + # checks to see if there is only one item in an array + # @return true if array only has one item def only_one_non_zero?( array ) found_non_zero = false array.each do |val|