Class: OrderListsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/order_lists_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /order_lists POST /order_lists.json



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/order_lists_controller.rb', line 50

def create
  @order_list = OrderList.new(order_list_params)
  @order_list.user = current_user

  respond_to do |format|
    if @order_list.save
      format.html { redirect_to @order_list, notice: t('controller.successfully_created', model: t('activerecord.models.order_list')) }
      format.json { render json: @order_list, status: :created, location: @order_list }
    else
      prepare_options
      format.html { render action: "new" }
      format.json { render json: @order_list.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /order_lists/1 DELETE /order_lists/1.json



90
91
92
93
94
95
96
97
# File 'app/controllers/order_lists_controller.rb', line 90

def destroy
  @order_list.destroy

  respond_to do |format|
    format.html { redirect_to order_lists_url }
    format.json { head :no_content }
  end
end

#editObject

GET /order_lists/1/edit



42
43
44
45
46
# File 'app/controllers/order_lists_controller.rb', line 42

def edit
  if params[:mode] == 'order'
    @order_list.edit_mode = 'order'
  end
end

#indexObject

GET /order_lists GET /order_lists.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/order_lists_controller.rb', line 8

def index
  if @bookstore
    @order_lists = @bookstore.order_lists.page(params[:page])
  else
    @order_lists = OrderList.page(params[:page])
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @order_lists }
    format.rss  { render layout: false }
    format.atom
  end
end

#newObject

GET /order_lists/new GET /order_lists/new.json



34
35
36
37
38
39
# File 'app/controllers/order_lists_controller.rb', line 34

def new
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @order_list }
  end
end

#showObject

GET /order_lists/1 GET /order_lists/1.json



25
26
27
28
29
30
# File 'app/controllers/order_lists_controller.rb', line 25

def show
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @order_list }
  end
end

#updateObject

PUT /order_lists/1 PUT /order_lists/1.json



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/order_lists_controller.rb', line 68

def update

  respond_to do |format|
    if @order_list.update_attributes(order_list_params)
      if @order_list.edit_mode == 'order'
        @order_list.transition_to(:ordered)
        @order_list.save(validate: false)
        format.html { redirect_to purchase_requests_url(order_list_id: @order_list.id), notice: t('controller.successfully_updated', model: t('activerecord.models.order_list')) }
      else
        format.html { redirect_to @order_list , notice: t('controller.successfully_updated', model: t('activerecord.models.order_list')) }
      end
      format.json { head :no_content }
    else
      prepare_options
      format.html { render action: "edit" }
      format.json { render json: @order_list.errors, status: :unprocessable_entity }
    end
  end
end