Class: SuppliersController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Instance Method Details

#createObject


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

def create    
  @supplier = Supplier.new(params[:supplier])
  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 => e
    flash[:error] = I18n.t('errors.general_msg', :msg => e.message)
    redirect_to @supplier
end

#editObject


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

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


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

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


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_attributes(params[:supplier])
    flash[:notice] = I18n.t('suppliers.update.notice')
    redirect_to @supplier
  else
    render :action => 'edit'
  end
end