Class: CheckinsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CheckinsController
- Defined in:
- app/controllers/checkins_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /checkins POST /checkins.json.
-
#destroy ⇒ Object
DELETE /checkins/1 DELETE /checkins/1.json.
-
#edit ⇒ Object
GET /checkins/1/edit.
-
#index ⇒ Object
GET /checkins GET /checkins.json.
-
#new ⇒ Object
GET /checkins/new.
-
#show ⇒ Object
GET /checkins/1 GET /checkins/1.json.
-
#update ⇒ Object
PUT /checkins/1 PUT /checkins/1.json.
Instance Method Details
#create ⇒ Object
POST /checkins POST /checkins.json
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/checkins_controller.rb', line 60 def create unless @basket access_denied; return end @checkin.basket = @basket @checkin.librarian = current_user flash[:message] = '' respond_to do |format| if @checkin.save = @checkin.item_checkin(current_user) if @checkin.checkout flash[:message] << t('checkin.successfully_checked_in') else flash[:message] << t('checkin.not_checked_out') end flash[:message] << if format.html { redirect_to checkins_url(basket_id: @checkin.basket_id) } format.json { render json: @checkin, status: :created, location: @checkin } format.js { redirect_to checkins_url(basket_id: @basket.id, format: :js) } else @checkins = @basket.checkins.page(1) format.html { render action: "new" } format.json { render json: @checkin.errors, status: :unprocessable_entity } format.js { render action: "index" } end end end |
#destroy ⇒ Object
DELETE /checkins/1 DELETE /checkins/1.json
109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/checkins_controller.rb', line 109 def destroy #@checkin = Checkin.find(params[:id]) @checkin.destroy respond_to do |format| format.html { redirect_to checkins_url } format.json { head :no_content } end end |
#edit ⇒ Object
GET /checkins/1/edit
54 55 56 |
# File 'app/controllers/checkins_controller.rb', line 54 def edit #@checkin = Checkin.find(params[:id]) end |
#index ⇒ Object
GET /checkins GET /checkins.json
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/checkins_controller.rb', line 8 def index if @basket @checkins = @basket.checkins.page(params[:page]) else @checkins = Checkin.page(params[:page]) end respond_to do |format| format.html # index.html.erb format.json { render json: @checkins } format.js end end |
#new ⇒ Object
GET /checkins/new
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/checkins_controller.rb', line 34 def new flash[:message] = nil if flash[:checkin_basket_id] @basket = Basket.find(flash[:checkin_basket_id]) else @basket = Basket.new @basket.user = current_user @basket.save! end @checkin = Checkin.new @checkins = Kaminari::paginate_array([]).page(1) flash[:checkin_basket_id] = @basket.id respond_to do |format| format.html # new.html.erb format.json { render json: @checkin } end end |
#show ⇒ Object
GET /checkins/1 GET /checkins/1.json
24 25 26 27 28 29 30 31 |
# File 'app/controllers/checkins_controller.rb', line 24 def show #@checkin = Checkin.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @checkin } end end |
#update ⇒ Object
PUT /checkins/1 PUT /checkins/1.json
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/checkins_controller.rb', line 92 def update @checkin.assign_attributes(checkin_params) @checkin.librarian = current_user respond_to do |format| if @checkin.save format.html { redirect_to @checkin, notice: t('controller.successfully_updated', model: t('activerecord.models.checkin')) } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @checkin.errors, status: :unprocessable_entity } end end end |