Class: PlanMyStuff::ProjectItems::AssignmentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- PlanMyStuff::ProjectItems::AssignmentsController
- Defined in:
- app/controllers/plan_my_stuff/project_items/assignments_controller.rb
Overview
Handles assigning and unassigning project item assignees via CRUD-style routes. Backs the assign/unassign forms on the project board view (T-047).
PATCH /projects/:project_id/items/:item_id/assignment -> update (assign) DELETE /projects/:project_id/items/:item_id/assignment -> destroy (unassign)
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /projects/:project_id/items/:item_id/assignment.
-
#update ⇒ Object
PATCH /projects/:project_id/items/:item_id/assignment.
Instance Method Details
#destroy ⇒ Object
DELETE /projects/:project_id/items/:item_id/assignment
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/plan_my_stuff/project_items/assignments_controller.rb', line 27 def destroy if params[:username].blank? flash[:error] = 'Username is required to unassign.' redirect_to(plan_my_stuff.project_path(params[:project_id])) return end item = find_project_item current_assignees = item.field_values['Assignees'] || [] remaining = current_assignees - [params[:username]] item.assign!(remaining) flash[:success] = "#{params[:username]} unassigned." redirect_to(plan_my_stuff.project_path(params[:project_id])) rescue ArgumentError, PMS::Error => e flash[:error] = e. redirect_to(plan_my_stuff.project_path(params[:project_id])) end |
#update ⇒ Object
PATCH /projects/:project_id/items/:item_id/assignment
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/plan_my_stuff/project_items/assignments_controller.rb', line 13 def update item = find_project_item assignees = parse_assignees(params[:assignee]) item.assign!(assignees) flash[:success] = "Item assigned to #{assignees.join(', ')}." redirect_to(plan_my_stuff.project_path(params[:project_id])) rescue ArgumentError, PMS::Error => e flash[:error] = e. redirect_to(plan_my_stuff.project_path(params[:project_id])) end |