obdev/app/controllers/employers_controller.rb

70 lines
1.5 KiB
Ruby
Raw Normal View History

class EmployersController < ApplicationController
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
end
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
end
end
# DELETE /employers/:id
def destroy
@employer.destroy
redirect_to employers_url, notice: 'Employer was successfully destroyed.'
end
# 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
private
def set_employer
@employer = Employer.find(params[:id])
end
def employer_params
params.require(:employer).permit(:name, :address, :phone, :email, :tin, :dob, :ssn, :gender)
end
end