Class: AcceptsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /accepts POST /accepts.json



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/accepts_controller.rb', line 67

def create
  unless @basket
    access_denied; return
  end
  @accept = Accept.new(accept_params)
  @accept.basket = @basket
  @accept.librarian = current_user

  flash[:message] = ''
  if @accept.item_identifier.blank?
    flash[:message] << t('accept.enter_item_identifier') if @accept.item_identifier.blank?
  else
    item = Item.where(item_identifier: @accept.item_identifier.to_s.strip).first
  end
  @accept.item = item

  respond_to do |format|
    if @accept.save
      flash[:message] << t('accept.successfully_accepted', model: t('activerecord.models.accept'))
      format.html { redirect_to accepts_url(basket_id: @basket.id) }
      format.json { render json: @accept, status: :created, location:  @accept }
      format.js { redirect_to accepts_url(basket_id: @basket.id, format: :js) }
    else
      @accepts = @basket.accepts.page(params[:page])
      format.html { render action: "index" }
      format.json { render json: @accept.errors, status: :unprocessable_entity }
      format.js { render action: "index" }
    end
  end
end

#destroyObject

DELETE /accepts/1 DELETE /accepts/1.json



114
115
116
117
118
119
120
121
# File 'app/controllers/accepts_controller.rb', line 114

def destroy
  @accept.destroy

  respond_to do |format|
    format.html { redirect_to accepts_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.accept')) }
    format.json { head :no_content }
  end
end

#editObject

GET /accepts/new GET /accepts/1/edit



62
63
# File 'app/controllers/accepts_controller.rb', line 62

def edit
end

#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] == 'text'
    @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.text
  end
end

#newObject

GET /new GET /new.json



47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/accepts_controller.rb', line 47

def new
  @basket = Basket.new
  @basket.user = current_user
  @basket.save!
  @accept = Accept.new
  @accepts = []

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

#showObject

GET /accepts/1 GET /accepts/1.json



38
39
40
41
42
43
# File 'app/controllers/accepts_controller.rb', line 38

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

#updateObject

PUT /accepts/1 PUT /accepts/1.json



100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/accepts_controller.rb', line 100

def update
  respond_to do |format|
    if @accept.update(accept_params)
      format.html { redirect_to @accept, notice: t('controller.successfully_updated', model: t('activerecord.models.accept')) }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @accept.errors, status: :unprocessable_entity }
    end
  end
end