Class: HrLite::LeaveRequestsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- HrLite::LeaveRequestsController
- Defined in:
- app/controllers/hr_lite/leave_requests_controller.rb
Overview
Employee self-service: always scoped to hr_current_user — a foreign id 404s, never 403s.
Instance Method Summary collapse
Instance Method Details
#cancel ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/hr_lite/leave_requests_controller.rb', line 29 def cancel request = own_requests.find(params[:id]) if request.cancellable_by?(hr_current_user) request.cancel!(actor: hr_current_user) redirect_to leave_requests_path, notice: "Leave cancelled." else redirect_to leave_requests_path, alert: "This request can no longer be cancelled." end end |
#create ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/hr_lite/leave_requests_controller.rb', line 19 def create @request = LeaveRequest.new(request_params.merge(user_id: hr_current_user.id)) if @request.save redirect_to leave_requests_path, notice: "Leave request submitted." else @balances = balance_cards render :new, status: :unprocessable_entity end end |
#index ⇒ Object
5 6 7 8 |
# File 'app/controllers/hr_lite/leave_requests_controller.rb', line 5 def index @requests = paginate(own_requests.recent_first.includes(:leave_type)) @balances = balance_cards end |
#new ⇒ Object
14 15 16 17 |
# File 'app/controllers/hr_lite/leave_requests_controller.rb', line 14 def new @request = LeaveRequest.new(start_date: Date.current, end_date: Date.current) @balances = balance_cards end |
#show ⇒ Object
10 11 12 |
# File 'app/controllers/hr_lite/leave_requests_controller.rb', line 10 def show @request = own_requests.find(params[:id]) end |