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
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 |
# File 'app/controllers/withdraws_controller.rb', line 67 def create unless @basket access_denied; return end @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
113 114 115 116 117 118 119 120 |
# File 'app/controllers/withdraws_controller.rb', line 113 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
62 63 |
# File 'app/controllers/withdraws_controller.rb', line 62 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] == 'txt' @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.txt end end |
#new ⇒ Object
GET /new GET /new.json
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/withdraws_controller.rb', line 47 def new @basket = Basket.new @basket.user = current_user @basket.save! @withdraw = 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
99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/withdraws_controller.rb', line 99 def update respond_to do |format| if @withdraw.update_attributes(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 |