Created
January 31, 2018 14:22
-
-
Save austinklenk/8478ff45c16c388b5fcb41b7eae14b01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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