Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module Service
class CustomersController < BaseController
before_action :set_customer, only: [:show, :edit, :update, :destroy]
# Listing out all customers from table
def index
@customers = Service::Customer.all
end
# Viewing customer
def show
@customer_vehicles = @customer.vehicles
end
## Initializing new customer form
def new
@customer = Service::Customer.new(customer_params)
end
## Editing of customer
def edit
end
## Creating of new customer
def create
@customer = Service::Customer.new(customer_params)
respond_to do |format|
if @customer.save
format.html { redirect_to service_customer_path(@customer), notice: 'Customer was successfully created.' }
else
format.html { render :new }
end
end
end
def update
respond_to do |format|
if @customer.update(customer_params)
format.html { redirect_to service_customer_path(@customer), notice: 'Customer updated.' }
else
format.html { render :new }
end
end
end
private ## Private Methods
# setting the instance variable for customer
def set_customer
@customer = Service::Customer.find(params[:id])
end
# letting fields through the controller to access the database.
def customer_params
params.require(:customer).permit(:title, :first_name, :middle_name, :last_name, :company_name, :primary_email, :secondary_email, :primary_phone, :secondary_phone, :fax_phone)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.