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


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

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


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

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

#editObject


39
40
41
# File 'app/controllers/suppliers_controller.rb', line 39

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

#indexObject


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

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


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

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


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

def shared_suppliers
  @shared_suppliers = SharedSupplier.all
end

#showObject


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

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

#updateObject


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

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