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