Sha256: 7e7a2f0279826396e695be992087cf9b4add17c771eb8ac3a2f1d60444296951

Contents?: true

Size: 1.59 KB

Versions: 17

Compression:

Stored size: 1.59 KB

Contents

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 collection_edit
    @collection = Employee::Collection.find(params[:ids])
    redirect_to employees_path, alert: 'No employees selected' if @collection.empty?
  end

  def collection_update
    @collection = Employee::Collection.find(params[:ids])
    if @collection.update params[:collection]
      redirect_to employees_path, notice: 'Collection is updated'
    else
      render 'collection_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, :vegan)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
record_collection-0.10.4 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.10.3 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.10.2 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.10.1 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.10.0 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.9.2 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.9.1 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.9.0 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.8.3 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.8.2 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.8.1 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.7.5 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.7.4 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.7.3 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.7.2 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.7.1 spec/dummy/app/controllers/employees_controller.rb
record_collection-0.7.0 spec/dummy/app/controllers/employees_controller.rb