Files
sx-fc/app/controllers/origami/commissioners_controller.rb
2017-08-21 17:31:17 +06:30

76 lines
2.2 KiB
Ruby

class Origami::CommissionersController < BaseOrigamiController
before_action :set_commissioner, only: [:show, :edit, :update, :destroy]
# GET /commissioners
# GET /commissioners.json
def index
@commissioners = Commissioner.all
end
# GET /commissioners/1
# GET /commissioners/1.json
def show
end
# GET /commissioners/new
def new
@commissioner = Commissioner.new
@employee = Employee.all.order('name asc')
end
# GET /commissioners/1/edit
def edit
end
# POST /commissioners
# POST /commissioners.json
def create
@commissioner = Commissioner.new(commissioner_params)
@commissioner.created_by = current_user.id
respond_to do |format|
if @commissioner.save
format.html { redirect_to origami_commissioners_path , notice: 'Commissioner was successfully created.' }
format.json { render :show, status: :created, location: @commissioner }
else
format.html { render :new }
format.json { render json: @commissioner.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /commissioners/1
# PATCH/PUT /commissioners/1.json
def update
respond_to do |format|
if @commissioner.update(commissioner_params)
format.html { redirect_to origami_commissioner_path(@commissioner) , notice: 'Commissioner was successfully updated.' }
format.json { render :show, status: :ok, location: @commissioner }
else
format.html { render :edit }
format.json { render json: @commissioner.errors, status: :unprocessable_entity }
end
end
end
# DELETE /commissioners/1
# DELETE /commissioners/1.json
def destroy
@commissioner.destroy
respond_to do |format|
format.html { redirect_to origami_commissioners_path , notice: 'Commissioner was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_commissioner
@commissioner = Commissioner.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def commissioner_params
params.require(:commissioner).permit(:name,:emp_id,:created_by,:commission_type, :is_active)
end
end