50 lines
846 B
Ruby
50 lines
846 B
Ruby
class CustomersController < ApplicationController
|
|
before_action :authenticate_user!
|
|
|
|
|
|
def index
|
|
@customers = Customer.all
|
|
end
|
|
|
|
def new
|
|
@customer = Customer.new
|
|
end
|
|
|
|
def create
|
|
@customer = Customer.new(customer_params)
|
|
if @customer.save
|
|
redirect_to customers_path
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@customer = Customer.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@customer = Customer.find(params[:id])
|
|
|
|
if @customer.update(customer_params)
|
|
redirect_to customers_path
|
|
else
|
|
render 'edit'
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@customer = Customer.find(params[:id])
|
|
@customer.destroy unless @customer.blank?
|
|
|
|
redirect_to customers_path
|
|
end
|
|
|
|
|
|
private
|
|
def customer_params
|
|
params.require(:customer).permit(:name, :street, :nip, :regon, :postcode, :city)
|
|
end
|
|
|
|
end
|