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
@vehicle = Vehicle.find_by_id(params[:id]) begin
if not @vehicle @vehicle = Vehicle.find_by_id(params[:id])
flash[:error] = "Vehicle Not Found" rescue ActiveRecord::RecordNotFound
redirect_to :index render_404
end end
end end
# return an HTML form for editing a vehicle # return an HTML form for editing a vehicle
def edit def edit
@vehicle = Vehicle.find_by_id(params[:id]) begin
@customers = Customer.all.order(:name) @vehicle = Vehicle.find_by_id(params[:id])
@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 redirect_to action: :index
flash[:error] = "No Vehicle Found" rescue ActiveRecord::RecordNotFound
render_404
end end
redirect_to action: :index
end end
end end