Class: Comable::Admin::DraftOrdersController

Inherits:
ApplicationController show all
Includes:
PermittedAttributes
Defined in:
app/controllers/comable/admin/draft_orders_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #respond_to_export_with

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/comable/admin/draft_orders_controller.rb', line 23

def create
  if save_order_as_draft
    @order.update!(draft: false) if @order.completed?
    redirect_to admin_order_path, notice: Comable.t('successful')
  else
    build_associations
    flash.now[:alert] = Comable.t('failure')
    render :new
  end
end

#editObject



34
35
# File 'app/controllers/comable/admin/draft_orders_controller.rb', line 34

def edit
end

#indexObject



10
11
12
13
# File 'app/controllers/comable/admin/draft_orders_controller.rb', line 10

def index
  @q = Comable::Order.draft.ransack(params[:q])
  @orders = @q.result.page(params[:page]).per(15).recent.accessible_by(current_ability)
end

#newObject



19
20
21
# File 'app/controllers/comable/admin/draft_orders_controller.rb', line 19

def new
  build_associations
end

#showObject



15
16
17
# File 'app/controllers/comable/admin/draft_orders_controller.rb', line 15

def show
  render :edit
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/comable/admin/draft_orders_controller.rb', line 37

def update
  @order.attributes = order_params

  if save_order_as_draft
    @order.update!(draft: false) if @order.completed?
    redirect_to admin_order_path, notice: Comable.t('successful')
  else
    flash.now[:alert] = Comable.t('failure')
    render :edit
  end
end