Class: AcceptsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- AcceptsController
- Defined in:
- app/controllers/accepts_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /accepts POST /accepts.json.
-
#destroy ⇒ Object
DELETE /accepts/1 DELETE /accepts/1.json.
-
#edit ⇒ Object
GET /accepts/new GET /accepts/1/edit.
-
#index ⇒ Object
GET /accepts GET /accepts.json.
-
#new ⇒ Object
GET /new GET /new.json.
-
#show ⇒ Object
GET /accepts/1 GET /accepts/1.json.
-
#update ⇒ Object
PUT /accepts/1 PUT /accepts/1.json.
Instance Method Details
#create ⇒ Object
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 |
# File 'app/controllers/accepts_controller.rb', line 67 def create unless @basket access_denied; return end @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 |
#destroy ⇒ Object
DELETE /accepts/1 DELETE /accepts/1.json
113 114 115 116 117 118 119 120 |
# File 'app/controllers/accepts_controller.rb', line 113 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 |
#edit ⇒ Object
GET /accepts/new GET /accepts/1/edit
62 63 |
# File 'app/controllers/accepts_controller.rb', line 62 def edit end |
#index ⇒ Object
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] == 'txt' @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.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/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 |
#show ⇒ Object
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 |
#update ⇒ Object
PUT /accepts/1 PUT /accepts/1.json
99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/accepts_controller.rb', line 99 def update respond_to do |format| if @accept.update_attributes(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 |