2024-01-17 01:21:20 -06:00
|
|
|
class EmployersController < ApplicationController
|
2024-01-19 18:25:59 -06:00
|
|
|
before_action :set_employer, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
|
|
# GET /employers
|
|
|
|
def index
|
|
|
|
@employers = Employer.order(:name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /employers/:id
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /employers/new
|
|
|
|
def new
|
|
|
|
@employer = Employer.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /employers
|
|
|
|
def create
|
|
|
|
@employer = Employer.new(employer_params)
|
|
|
|
if @employer.save
|
|
|
|
redirect_to @employer, notice: 'Employer was successfully created.'
|
|
|
|
else
|
|
|
|
render :new
|
2024-01-17 01:21:20 -06:00
|
|
|
end
|
2024-01-19 18:25:59 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /employers/:id/edit
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
# PATCH/PUT /employers/:id
|
|
|
|
def update
|
|
|
|
if @employer.update(employer_params)
|
|
|
|
redirect_to @employer, notice: 'Employer was successfully updated.'
|
|
|
|
else
|
|
|
|
render :edit
|
2024-01-17 01:21:20 -06:00
|
|
|
end
|
2024-01-19 18:25:59 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /employers/:id
|
|
|
|
def destroy
|
|
|
|
@employer.destroy
|
|
|
|
redirect_to employers_url, notice: 'Employer was successfully destroyed.'
|
|
|
|
end
|
|
|
|
|
2024-01-19 23:38:15 -06:00
|
|
|
# GET /employers/search
|
|
|
|
# This action responds to the auto-complete AJAX requests
|
|
|
|
def search
|
|
|
|
if params[:term].present?
|
|
|
|
@employers = Employer.where("name LIKE ?", "%#{params[:term]}%")
|
|
|
|
else
|
|
|
|
@employers = Employer.none
|
|
|
|
end
|
|
|
|
|
|
|
|
# Respond with a JSON array of employer names and IDs
|
|
|
|
render json: @employers.map { |e| { label: e.name, value: e.id } }
|
|
|
|
end
|
|
|
|
|
2024-01-19 18:25:59 -06:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_employer
|
2024-01-17 01:21:20 -06:00
|
|
|
@employer = Employer.find(params[:id])
|
|
|
|
end
|
2024-01-19 18:25:59 -06:00
|
|
|
|
|
|
|
def employer_params
|
|
|
|
params.require(:employer).permit(:name, :address, :phone, :email, :tin, :dob, :ssn, :gender)
|
|
|
|
end
|
|
|
|
end
|