tab/app/controllers/requests_controller.rb

36 lines
724 B
Ruby
Raw Normal View History

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
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
@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
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