class EmployeesController < ApplicationController before_action :set_employee, only: [:show, :edit, :update, :destroy] # GET /employees def index @employees = Employee.all end # GET /employees/1 def show end # GET /employees/new def new @employee = Employee.new end # GET /employees/1/edit def edit end # POST /employees def create @employee = Employee.new(employee_params) if @employee.save redirect_to @employee, notice: 'Employee was successfully created.' else render :new end end # PATCH/PUT /employees/1 def update if @employee.update(employee_params) redirect_to @employee, notice: 'Employee was successfully updated.' else render :edit end end # DELETE /employees/1 def destroy @employee.destroy redirect_to employees_url, notice: 'Employee was successfully destroyed.' end def batch_edit @collection = Employee::Collection.find(params[:ids]) redirect_to employees_path, alert: 'No employees selected' if @collection.empty? end def batch_update @collection = Employee::Collection.find(params[:ids]) if @collection.update params[:collection] redirect_to employees_path, notice: 'Collection is updated' else render 'batch_edit' end end private # Use callbacks to share common setup or constraints between actions. def set_employee @employee = Employee.find(params[:id]) end # Only allow a trusted parameter "white list" through. def employee_params params.require(:employee).permit(:name, :section) end end