2017-01-09 15:46:43 +01:00
|
|
|
class RequestsController < ApplicationController
|
2017-01-09 16:22:58 +01:00
|
|
|
load_and_authorize_resource :user, only: :index
|
2017-01-09 15:46:43 +01:00
|
|
|
|
|
|
|
before_action :load_request, only: [:confirm, :decline]
|
|
|
|
authorize_resource :request, only: [:confirm, :decline]
|
|
|
|
|
|
|
|
def index
|
2017-01-09 16:22:58 +01:00
|
|
|
@requests = @user.incoming_requests.group_by(&:status)
|
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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_request
|
|
|
|
@request = Request.find params[:request_id]
|
|
|
|
end
|
|
|
|
end
|