Class: CheckoutsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- CheckoutsController
- Defined in:
- app/controllers/checkouts_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /checkouts/1 DELETE /checkouts/1.json.
-
#edit ⇒ Object
GET /checkouts/1/edit.
-
#index ⇒ Object
GET /checkouts GET /checkouts.json.
-
#show ⇒ Object
GET /checkouts/1 GET /checkouts/1.json.
-
#update ⇒ Object
PUT /checkouts/1 PUT /checkouts/1.json.
Instance Method Details
#destroy ⇒ Object
DELETE /checkouts/1 DELETE /checkouts/1.json
126 127 128 129 130 131 132 133 134 135 |
# File 'app/controllers/checkouts_controller.rb', line 126 def destroy user = @checkout.user @checkout.user_id = nil @checkout.save! respond_to do |format| format.html { redirect_to user_checkouts_url(user), :notice => t('controller.successfully_deleted', :model => t('activerecord.models.checkout')) } format.json { head :no_content } end end |
#edit ⇒ Object
GET /checkouts/1/edit
86 87 88 |
# File 'app/controllers/checkouts_controller.rb', line 86 def edit @new_due_date = @checkout.get_new_due_date end |
#index ⇒ Object
GET /checkouts GET /checkouts.json
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/checkouts_controller.rb', line 13 def index if params[:icalendar_token].present? icalendar_user = User.where(:checkout_icalendar_token => params[:icalendar_token]).first if icalendar_user.blank? raise ActiveRecord::RecordNotFound else checkouts = icalendar_user.checkouts.not_returned.order('checkouts.id DESC') end else unless current_user access_denied; return end end unless icalendar_user if current_user.try(:has_role?, 'Librarian') if @user checkouts = @user.checkouts.not_returned.order('checkouts.id DESC').page(params[:page]) else if params[:view] == 'overdue' if params[:days_overdue] date = params[:days_overdue].to_i.days.ago.beginning_of_day else date = 1.days.ago.beginning_of_day end checkouts = Checkout.overdue(date).order('checkouts.id DESC').page(params[:page]) else checkouts = Checkout.not_returned.order('checkouts.id DESC').page(params[:page]) end end else # 一般ユーザ if current_user == @user redirect_to checkouts_url(:format => params[:format]) return else if @user access_denied return else checkouts = current_user.checkouts.not_returned.order('checkouts.id DESC').page(params[:page]) end end end end @days_overdue = params[:days_overdue] ||= 1 if params[:format] == 'csv' @checkouts = checkouts else @checkouts = checkouts.page(params[:page]) end respond_to do |format| format.html # index.html.erb format.json { render :json => @checkouts } format.rss { render :layout => false } format.ics format.csv format.atom end end |
#show ⇒ Object
GET /checkouts/1 GET /checkouts/1.json
78 79 80 81 82 83 |
# File 'app/controllers/checkouts_controller.rb', line 78 def show respond_to do |format| format.html # show.html.erb format.json { render :json => @checkout } end end |
#update ⇒ Object
PUT /checkouts/1 PUT /checkouts/1.json
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/checkouts_controller.rb', line 92 def update if @checkout.reserved? flash[:notice] = t('checkout.this_item_is_reserved') redirect_to edit_checkout_url(@checkout) return end if @checkout.over_checkout_renewal_limit? flash[:notice] = t('checkout.excessed_renewal_limit') redirect_to edit_checkout_url(@checkout) return end if @checkout.overdue? flash[:notice] = t('checkout.you_have_overdue_item') unless current_user.has_role?('Librarian') redirect_to edit_checkout_url(@checkout) return end end @checkout.reload @checkout.checkout_renewal_count += 1 respond_to do |format| if @checkout.update_attributes(params[:checkout]) format.html { redirect_to @checkout, :notice => t('controller.successfully_updated', :model => t('activerecord.models.checkout')) } format.json { head :no_content } else format.html { render :action => "edit" } format.json { render :json => @checkout.errors, :status => :unprocessable_entity } end end end |