Update customers_controller.rb

This commit is contained in:
2016-05-11 09:26:21 -04:00
parent ec56b59d57
commit 5c9cd88279

View File

@@ -38,42 +38,48 @@ class CustomersController < ApplicationController
# display a specific customer # display a specific customer
def show def show
begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
if @customer
@vehicles = @customer.vehicles.paginate(:page => params[:page]) @vehicles = @customer.vehicles.paginate(:page => params[:page])
@issues = @customer.issues @issues = @customer.issues
else rescue ActiveRecord::RecordNotFound
flash[:error] = "Customer Not Found" render_404
render :index
end end
end end
# return an HTML form for editing a customer # return an HTML form for editing a customer
def edit def edit
begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
end end
# update a specific customer # update a specific customer
def update def update
begin
@customer = Customer.find_by_id(params[:id]) @customer = Customer.find_by_id(params[:id])
if @customer.update_attributes(params[:vehicle]) if @customer.update_attributes(params[:vehicle])
flash[:notice] = "Customer updated" flash[:notice] = "Customer updated"
redirect_to @customer redirect_to @customer
else else
flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors
redirect_to edit_customer_path redirect_to edit_customer_path
end end
flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors rescue ActiveRecord::RecordNotFound
render_404
end
end end
def destroy def destroy
begin begin
Customer.find_by_id(params[:id]).destroy Customer.find_by_id(params[:id]).destroy
flash[:notice] = "Customer deleted successfully" flash[:notice] = "Customer deleted successfully"
rescue
flash[:error] = "No Customer Found"
end
redirect_to action: :index redirect_to action: :index
rescue ActiveRecord::RecordNotFound
render_404
end
end end
end end