Created
October 29, 2019 18:50
-
-
Save faizaankhan/fe72faa9a1b0b3661c8d65fbbc7c2294 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AssociatesController < ApplicationController | |
before_action:authenticate_user! | |
def new | |
@associate= params || {} | |
@associate=Associate.new() | |
end | |
def index | |
if current_user[:role]=="associate" | |
@associates = current_user.associates.paginate(page: params[:page], per_page: 3) | |
elsif current_user[:role]=="manager" | |
@associates = current_user.associates.paginate(page: params[:page], per_page: 3) | |
@associates_to_approve = Associate.where(user: current_user.subordinates).paginate(page: params[:page], per_page: 3) | |
end | |
end | |
def edit | |
@associate = Associate.find(params[:id]) | |
end | |
def update | |
@associate = Associate.find_by_id(params[:id]) | |
if @associate.update_attributes(associate_params) | |
flash[:notice]= "successfully updated" | |
redirect_to associates_index_path | |
else | |
flash[:notice]= "operation failed" | |
end | |
end | |
def destroy | |
@associate = Associate.find(params[:id]) | |
@associate.destroy | |
flash[:notice]= "successfully deleted" | |
redirect_to associate_path(@associate) | |
end | |
def create | |
@associate=current_user.associates.new(associate_params) | |
if @associate.save | |
flash[:notice]= "Request generated successfully" | |
redirect_to associates_index_path | |
else | |
render 'new' | |
end | |
end | |
def accept_request | |
@associate = Associate.find(params[:id]) | |
@associate.update_attributes(status: "Approved") | |
redirect_to associates_index_path | |
end | |
def cancel_request | |
@associate = Associate.find(params[:id]) | |
@associate.update_attributes(status: "Rejected") | |
redirect_to associates_index_path | |
end | |
def associate_params | |
params.require(:associate).permit( :leave_approval, :start_date, :end_date, :type_of_request, :cerner_id, :email) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment