Update vehicles_controller.rb

This commit is contained in:
2016-05-06 12:25:30 -04:00
parent 5d6ff72ef7
commit a70561b5bd

View File

@@ -36,10 +36,10 @@ class VehiclesController < ApplicationController
flash[:notice] = "New Vehicle Created"
redirect_to @vehicle
else
@customers = Customer.all.order(:name)
render :edit
flash[:error] = @vehicle.errors.full_messages.to_sentence
redirect_to :new
end
flash[:error] = @vehicle.errors.full_messages.to_sentence if @vehicle.errors
end
# display a specific vehicle
@@ -49,8 +49,7 @@ class VehiclesController < ApplicationController
@customer = @vehicle.customer.name if @vehicle.customer
else
flash[:error] = "Vehicle Not Found"
@customers = Customer.all.order(:name)
render :index
redirect_to :index
end
end
@@ -63,14 +62,13 @@ class VehiclesController < ApplicationController
# update a specific vehicle
def update
@customers = Customer.all.order(:name)
@customer = params[:customer]
@vehicle = Vehicle.find_by_id(params[:id])
if @vehicle.update_attributes(params[:vehicle])
flash[:notice] = "Vehicle updated"
redirect_to @vehicle
else
render :edit
redirect_to :edit
end
flash[:error] = @vehicle.errors.full_messages.to_sentence if @vehicle.errors
end