Class: GroupOrdersController

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

Overview

Controller for all ordering-actions that are performed by a user who is member of an Ordergroup. Management actions that require the “orders” role are handled by the OrdersController.

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Instance Method Details

#archiveObject

Shows all Orders of the Ordergroup if selected, it shows all orders of the foodcoop


56
57
58
59
60
61
62
63
64
# File 'app/controllers/group_orders_controller.rb', line 56

def archive
  # get only orders belonging to the ordergroup
  @closed_orders = Order.closed.page(params[:page]).per(10)

  respond_to do |format|
    format.html # archive.html.haml
    format.js   # archive.js.erb
  end
end

#createObject


20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/group_orders_controller.rb', line 20

def create
  @group_order = GroupOrder.new(params[:group_order])
  begin
    @group_order.save_ordering!
    redirect_to group_order_url(@group_order), :notice => I18n.t('group_orders.create.notice')
  rescue ActiveRecord::StaleObjectError
    redirect_to group_orders_url, :alert => I18n.t('group_orders.create.error_stale')
  rescue => exception
    logger.error('Failed to update order: ' + exception.message)
    redirect_to group_orders_url, :alert => I18n.t('group_orders.create.error_general')
  end
end

#editObject


37
38
39
# File 'app/controllers/group_orders_controller.rb', line 37

def edit
  @ordering_data = @group_order.load_data
end

#indexObject

Index page.


11
12
# File 'app/controllers/group_orders_controller.rb', line 11

def index
end

#newObject


14
15
16
17
18
# File 'app/controllers/group_orders_controller.rb', line 14

def new
  ordergroup = params[:stock_order] ? nil : @ordergroup
  @group_order = @order.group_orders.build(:ordergroup => ordergroup, :updated_by => current_user)
  @ordering_data = @group_order.load_data
end

#showObject


33
34
35
# File 'app/controllers/group_orders_controller.rb', line 33

def show
  @order= @group_order.order
end

#updateObject


41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/group_orders_controller.rb', line 41

def update
  @group_order.attributes = params[:group_order]
  begin
    @group_order.save_ordering!
    redirect_to group_order_url(@group_order), :notice => I18n.t('group_orders.update.notice')
  rescue ActiveRecord::StaleObjectError
    redirect_to group_orders_url, :alert => I18n.t('group_orders.update.error_stale')
  rescue => exception
    logger.error('Failed to update order: ' + exception.message)
    redirect_to group_orders_url, :alert => I18n.t('group_orders.update.error_general')
  end
end