Class: ApprovalGroupsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/approval_groups_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/approval_groups_controller.rb', line 16

def create
  p_hash = params[:approval_group]
  @approval_group = ApprovalGroup.create!(name: p_hash[:name], flow: p_hash[:flow])
  @requester = User.find_or_create_by(email_address: p_hash[:requester])
  @approver1 = User.find_or_create_by(email_address: p_hash[:approver1])
  @approver2 = User.find_or_create_by(email_address: p_hash[:approver2])
  UserRole.create!(user_id: @approver1.id, approval_group_id: @approval_group.id, role: 'approver')
  UserRole.create!(user_id: @approver2.id, approval_group_id: @approval_group.id, role: 'approver')
  UserRole.create!(user_id: @requester.id, approval_group_id: @approval_group.id, role: 'requester')
  flash[:success] = "Group created successfully"
  redirect_to @approval_group
end

#indexObject


4
5
6
# File 'app/controllers/approval_groups_controller.rb', line 4

def index
  @groups = ApprovalGroup.all
end

#newObject


12
13
14
# File 'app/controllers/approval_groups_controller.rb', line 12

def new
  @approval_group = ApprovalGroup.new
end

#searchObject


29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/approval_groups_controller.rb', line 29

def search
  @groups = []
  user = User.find_by_email_address(params[:email])
  unless user.nil?
    roles = UserRole.where("user_id = ? AND role='requester'", user.id ).select(:approval_group_id).distinct.map(&:approval_group_id)
    @groups = ApprovalGroup.where(id: roles )
  end

  render :index
end

#showObject


8
9
10
# File 'app/controllers/approval_groups_controller.rb', line 8

def show
  @approval_group = ApprovalGroup.find(params[:id])
end