diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb index bc46ac5..3e6d392 100644 --- a/app/controllers/vehicles_controller.rb +++ b/app/controllers/vehicles_controller.rb @@ -61,13 +61,17 @@ class VehiclesController < ApplicationController # update a specific vehicle def update @customer = params[:customer] - @vehicle = Vehicle.find_by_id(params[:id]) - if @vehicle.update_attributes(params[:vehicle]) - flash[:notice] = "Vehicle updated" - redirect_to @vehicle - else - flash[:error] = @vehicle.errors.full_messages.to_sentence if @vehicle.errors - redirect_to edit_vehicle_path + begin + @vehicle = Vehicle.find_by_id(params[:id]) + if @vehicle.update_attributes(params[:vehicle]) + flash[:notice] = "Vehicle updated" + redirect_to @vehicle + else + flash[:error] = @vehicle.errors.full_messages.to_sentence if @vehicle.errors + redirect_to edit_vehicle_path + end + rescue ActiveRecord::RecordNotFound + render_404 end end