2017-01-09 15:46:43 +01:00
|
|
|
class RequestsController < ApplicationController
|
2019-03-24 22:31:03 +01:00
|
|
|
load_and_authorize_resource :user, find_by: :name
|
2017-01-09 15:46:43 +01:00
|
|
|
|
2019-05-31 04:50:55 +02:00
|
|
|
before_action :load_request, only: [:confirm, :decline, :cancel]
|
|
|
|
authorize_resource :request, id_param: :request_id, only: [:confirm, :decline, :cancel]
|
2017-01-09 15:46:43 +01:00
|
|
|
|
|
|
|
def index
|
2019-05-31 04:50:55 +02:00
|
|
|
@requests = @user.requests.group_by(&:status)
|
2019-04-10 14:15:20 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { }
|
|
|
|
format.json { render json: @requests }
|
|
|
|
end
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def confirm
|
|
|
|
@request.confirm!
|
2017-01-14 16:22:44 +01:00
|
|
|
redirect_to root_path
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def decline
|
|
|
|
@request.decline!
|
2017-01-14 16:22:44 +01:00
|
|
|
redirect_to root_path
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
2019-05-31 04:50:55 +02:00
|
|
|
def cancel
|
|
|
|
@request.cancel!
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
|
2017-01-09 15:46:43 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_request
|
|
|
|
@request = Request.find params[:request_id]
|
|
|
|
end
|
|
|
|
end
|