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