Class: WithdrawsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- WithdrawsController
- Defined in:
- app/controllers/withdraws_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /withdraws POST /withdraws.json.
-
#destroy ⇒ Object
DELETE /withdraws/1 DELETE /withdraws/1.json.
-
#edit ⇒ Object
GET /withdraws/new GET /withdraws/1/edit.
-
#index ⇒ Object
GET /withdraws GET /withdraws.json.
-
#new ⇒ Object
GET /new GET /new.json.
-
#show ⇒ Object
GET /withdraws/1 GET /withdraws/1.json.
-
#update ⇒ Object
PUT /withdraws/1 PUT /withdraws/1.json.
Instance Method Details
#create ⇒ Object
POST /withdraws POST /withdraws.json
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 97 |
# File 'app/controllers/withdraws_controller.rb', line 68 def create unless @basket access_denied; return end @withdraw = Withdraw.new(withdraw_params) @withdraw.basket = @basket @withdraw.librarian = current_user flash[:message] = '' if @withdraw.item_identifier.blank? flash[:message] << t('withdraw.enter_item_identifier') if @withdraw.item_identifier.blank? else item = Item.where(item_identifier: @withdraw.item_identifier.to_s.strip).first end @withdraw.item = item respond_to do |format| if @withdraw.save flash[:message] << t('withdraw.successfully_withdrawn', model: t('activerecord.models.withdraw')) format.html { redirect_to withdraws_url(basket_id: @basket.id) } format.json { render json: @withdraw, status: :created, location: @withdraw } format.js { redirect_to withdraws_url(basket_id: @basket.id, format: :js) } else @withdraws = @basket.withdraws.page(params[:page]) format.html { render action: "index" } format.json { render json: @withdraw.errors, status: :unprocessable_entity } format.js { render action: "index" } end end end |
#destroy ⇒ Object
DELETE /withdraws/1 DELETE /withdraws/1.json
115 116 117 118 119 120 121 122 |
# File 'app/controllers/withdraws_controller.rb', line 115 def destroy @withdraw.destroy respond_to do |format| format.html { redirect_to withdraws_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.withdraw')) } format.json { head :no_content } end end |
#edit ⇒ Object
GET /withdraws/new GET /withdraws/1/edit
63 64 |
# File 'app/controllers/withdraws_controller.rb', line 63 def edit end |
#index ⇒ Object
GET /withdraws GET /withdraws.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/withdraws_controller.rb', line 8 def index if params[:format] == 'text' @withdraws = Withdraw.order('withdraws.created_at DESC').page(params[:page]).per(65534) else if params[:withdraw] @query = params[:withdraw][:item_identifier].to_s.strip item = Item.where(item_identifier: @query).first if @query.present? end if item @withdraws = Withdraw.order('withdraws.created_at DESC').where(item_id: item.id).page(params[:page]) else if @basket @withdraws = @basket.withdraws.order('withdraws.created_at DESC').page(params[:page]) else @withdraws = Withdraw.order('withdraws.created_at DESC').page(params[:page]) end end end respond_to do |format| format.html # index.html.erb format.json { render json: @withdraws } format.js { @withdraw = Withdraw.new } format.text end end |
#new ⇒ Object
GET /new GET /new.json
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/withdraws_controller.rb', line 47 def new @basket = Basket.new @basket.user = current_user @basket.save! @withdraw = Withdraw.new @withdraw, :new? @withdraws = [] respond_to do |format| format.html # new.html.erb format.json { render json: @withdraw } end end |
#show ⇒ Object
GET /withdraws/1 GET /withdraws/1.json
38 39 40 41 42 43 |
# File 'app/controllers/withdraws_controller.rb', line 38 def show respond_to do |format| format.html # show.html.erb format.json { render json: @withdraw } end end |
#update ⇒ Object
PUT /withdraws/1 PUT /withdraws/1.json
101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/withdraws_controller.rb', line 101 def update respond_to do |format| if @withdraw.update(withdraw_params) format.html { redirect_to @withdraw, notice: t('controller.successfully_updated', model: t('activerecord.models.withdraw')) } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @withdraw.errors, status: :unprocessable_entity } end end end |