Update vehicles_controller.rb

This commit is contained in:
2016-05-11 09:23:35 -04:00
parent ee088c65f2
commit ec56b59d57

View File

@@ -41,17 +41,21 @@ class VehiclesController < ApplicationController
# display a specific vehicle # display a specific vehicle
def show def show
begin
@vehicle = Vehicle.find_by_id(params[:id]) @vehicle = Vehicle.find_by_id(params[:id])
if not @vehicle rescue ActiveRecord::RecordNotFound
flash[:error] = "Vehicle Not Found" render_404
redirect_to :index
end end
end end
# return an HTML form for editing a vehicle # return an HTML form for editing a vehicle
def edit def edit
begin
@vehicle = Vehicle.find_by_id(params[:id]) @vehicle = Vehicle.find_by_id(params[:id])
@customers = Customer.all.order(:name) @customers = Customer.all.order(:name)
rescue ActiveRecord::RecordNotFound
render_404
end
end end
# update a specific vehicle # update a specific vehicle
@@ -72,10 +76,10 @@ class VehiclesController < ApplicationController
begin begin
Vehicle.find_by_id(params[:id]).destroy Vehicle.find_by_id(params[:id]).destroy
flash[:notice] = "Vehicle deleted successfully" flash[:notice] = "Vehicle deleted successfully"
rescue
flash[:error] = "No Vehicle Found"
end
redirect_to action: :index redirect_to action: :index
rescue ActiveRecord::RecordNotFound
render_404
end
end end
end end