Method: AcceptsController#index

Defined in:
app/controllers/accepts_controller.rb

#indexObject

GET /accepts GET /accepts.json



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/accepts_controller.rb', line 8

def index
  if params[:format] == 'txt'
    @accepts = Accept.order('accepts.created_at DESC').page(params[:page]).per(65534)
  else
    if params[:accept]
      @query = params[:accept][:item_identifier].to_s.strip
      item = Item.where(item_identifier: @query).first if @query.present?
    end

    if item
      @accepts = Accept.order('accepts.created_at DESC').where(item_id: item.id).page(params[:page])
    else
      if @basket
        @accepts = @basket.accepts.order('accepts.created_at DESC').page(params[:page])
      else
        @accepts = Accept.order('accepts.created_at DESC').page(params[:page])
      end
    end
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @accepts }
    format.js { @accept = Accept.new }
    format.txt
  end
end