Class: SuppliersController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Methods included from PathHelper

#finance_group_transactions_path

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/suppliers_controller.rb', line 31

def create
  @supplier = Supplier.new(supplier_params)
  @supplier.supplier_category ||= SupplierCategory.first
  if @supplier.save
    flash[:notice] = I18n.t('suppliers.create.notice')
    redirect_to suppliers_path
  else
    render action: 'new'
  end
end

#destroyObject



52
53
54
55
56
57
58
59
60
# File 'app/controllers/suppliers_controller.rb', line 52

def destroy
  @supplier = Supplier.find(params[:id])
  @supplier.mark_as_deleted
  flash[:notice] = I18n.t('suppliers.destroy.notice')
  redirect_to suppliers_path
rescue StandardError => e
  flash[:error] = I18n.t('errors.general_msg', msg: e.message)
  redirect_to @supplier
end

#editObject



27
28
29
# File 'app/controllers/suppliers_controller.rb', line 27

def edit
  @supplier = Supplier.find(params[:id])
end

#indexObject



5
6
7
8
# File 'app/controllers/suppliers_controller.rb', line 5

def index
  @suppliers = Supplier.undeleted.order(:name)
  @deliveries = Delivery.recent
end

#newObject

new supplier if shared_supplier_id is given, the new supplier will filled whith its attributes



18
19
20
21
22
23
24
25
# File 'app/controllers/suppliers_controller.rb', line 18

def new
  if params[:shared_supplier_id]
    shared_supplier = SharedSupplier.find(params[:shared_supplier_id])
    @supplier = shared_supplier.suppliers.new(shared_supplier.autofill_attributes)
  else
    @supplier = Supplier.new
  end
end

#shared_suppliersObject

gives a list with all available shared_suppliers



63
64
65
# File 'app/controllers/suppliers_controller.rb', line 63

def shared_suppliers
  @shared_suppliers = SharedSupplier.all
end

#showObject



10
11
12
13
14
# File 'app/controllers/suppliers_controller.rb', line 10

def show
  @supplier = Supplier.find(params[:id])
  @deliveries = @supplier.deliveries.recent
  @orders = @supplier.orders.recent
end

#updateObject



42
43
44
45
46
47
48
49
50
# File 'app/controllers/suppliers_controller.rb', line 42

def update
  @supplier = Supplier.find(params[:id])
  if @supplier.update(supplier_params)
    flash[:notice] = I18n.t('suppliers.update.notice')
    redirect_to @supplier
  else
    render action: 'edit'
  end
end