Class: M::Icol::CustomersController

Inherits:
ApplicationController show all
Includes:
Approval2::ControllerAdditions
Defined in:
app/controllers/m/icol/customers_controller.rb

Instance Method Summary collapse

Instance Method Details

#approveObject



56
57
58
# File 'app/controllers/m/icol/customers_controller.rb', line 56

def approve
  redirect_to unapproved_records_path(group_name: 'icol')
end

#audit_logsObject



51
52
53
54
# File 'app/controllers/m/icol/customers_controller.rb', line 51

def audit_logs
  @record = Customer.unscoped.find(params[:id]) rescue nil
  @audit = @record.audits[params[:version_id].to_i] rescue nil
end

#createObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/m/icol/customers_controller.rb', line 12

def create
  @customer = Customer.new(params[:customer])
  if !@customer.valid?
    render "new"
  else
    @customer.created_by = current_user.id
    @customer.save!
    flash[:alert] = 'Customer successfully created and is pending for approval'
    redirect_to @customer
  end
end

#indexObject



45
46
47
48
49
# File 'app/controllers/m/icol/customers_controller.rb', line 45

def index
  customers = (params[:approval_status].present? and params[:approval_status] == 'U') ? Customer.unscoped.where("approval_status =?",'U').order("id desc") : Customer.order("id desc")
  @customers_count = customers.count
  @customers = customers.paginate(:per_page => 10, :page => params[:page]) rescue []
end

#newObject



8
9
10
# File 'app/controllers/m/icol/customers_controller.rb', line 8

def new
  @customer = Customer.new
end

#showObject



41
42
43
# File 'app/controllers/m/icol/customers_controller.rb', line 41

def show
  @customer = Customer.unscoped.find_by_id(params[:id])
end

#updateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/m/icol/customers_controller.rb', line 24

def update
  @customer = Customer.unscoped.find_by_id(params[:id])
  @customer.attributes = params[:customer]
  if !@customer.valid?
    render "edit"
  else
    @customer.updated_by = current_user.id
    @customer.save!
    flash[:alert] = 'Customer successfully modified successfully'
    redirect_to @customer
  end
  rescue ActiveRecord::StaleObjectError
    @customer.reload
    flash[:alert] = 'Someone edited the customer the same time you did. Please re-apply your changes to the customer.'
    render "edit"
end