Files
sx-fc/app/controllers/crm/customers_controller.rb
2017-06-06 14:16:40 +06:30

84 lines
2.4 KiB
Ruby

class Crm::CustomersController < ApplicationController
before_action :set_crm_customer, only: [:show, :edit, :update, :destroy]
# GET /crm/customers
# GET /crm/customers.json
def index
@crm_customers = Customer.all
@customers = Customer.new
@membership = Customer.get_member_group
respond_to do |format|
format.html # index.html.erb
format.json { render json: @crm_customers }
end
end
# GET /crm/customers/1
# GET /crm/customers/1.json
def show
end
# GET /crm/customers/new
def new
@crm_customer = Customer.new
@membership = Customer.get_member_group()
end
# GET /crm/customers/1/edit
def edit
end
# POST /crm/customers
# POST /crm/customers.json
def create
@crm_customer = Customer.new(customer_params)
respond_to do |format|
if @crm_customer.save
format.html { redirect_to @crm_customer, notice: 'Customer was successfully created.' }
format.json { render :show, status: :created, location: @crm_customer }
else
format.html { render :new }
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /crm/customers/1
# PATCH/PUT /crm/customers/1.json
def update
respond_to do |format|
if @crm_customer.update(customer_params)
format.html { redirect_to @crm_customer, notice: 'Customer was successfully updated.' }
format.json { render :show, status: :ok, location: @crm_customer }
else
format.html { render :edit }
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
end
end
end
# DELETE /crm/customers/1
# DELETE /crm/customers/1.json
def destroy
@crm_customer.destroy
respond_to do |format|
format.html { redirect_to crm_customers_url, notice: 'Customer was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_crm_customer
@crm_customer = Customer.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def customer_params
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code)
end
end