mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 08:54:23 -05:00
Update customers_controller.rb
This commit is contained in:
@@ -38,42 +38,48 @@ class CustomersController < ApplicationController
|
|||||||
|
|
||||||
# display a specific customer
|
# display a specific customer
|
||||||
def show
|
def show
|
||||||
@customer = Customer.find_by_id(params[:id])
|
begin
|
||||||
if @customer
|
@customer = Customer.find_by_id(params[:id])
|
||||||
@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
|
||||||
@customer = Customer.find_by_id(params[:id])
|
begin
|
||||||
|
@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
|
||||||
@customer = Customer.find_by_id(params[:id])
|
begin
|
||||||
if @customer.update_attributes(params[:vehicle])
|
@customer = Customer.find_by_id(params[:id])
|
||||||
flash[:notice] = "Customer updated"
|
if @customer.update_attributes(params[:vehicle])
|
||||||
redirect_to @customer
|
flash[:notice] = "Customer updated"
|
||||||
else
|
redirect_to @customer
|
||||||
redirect_to edit_customer_path
|
else
|
||||||
|
flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors
|
||||||
|
redirect_to edit_customer_path
|
||||||
|
end
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
flash[:error] = @customer.errors.full_messages.to_sentence if @customer.errors
|
|
||||||
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
|
redirect_to action: :index
|
||||||
flash[:error] = "No Customer Found"
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
end
|
end
|
||||||
redirect_to action: :index
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user