Class: AssignmentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AssignmentsController
- Defined in:
- app/controllers/assignments_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /assignments.
-
#destroy ⇒ Object
DELETE /assignments/1.
-
#index ⇒ Object
GET /assignments.
-
#new ⇒ Object
GET /assignments/new.
-
#show ⇒ Object
GET /assignments/1.
Instance Method Details
#create ⇒ Object
POST /assignments
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/assignments_controller.rb', line 34 def create resource_ids = assignment_params.values_at(:resource_ids, :resource_id).tap(&:compact!) resources = current_organization.resources.where(id: resource_ids) assignments = resources.map do |resource| Assignment.find_or_create_by!(resource: resource, user: assigned_user) end logger.info "Created '#{assignments}'" flash[:notice] = "Created #{assignments.count} #{'assignment'.pluralize(assignments.count)}" redirect_back fallback_location: [current_organization] end |
#destroy ⇒ Object
DELETE /assignments/1
49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/assignments_controller.rb', line 49 def destroy if assignment.destroy logger.info "Deleted #{assignment}" redirect_to organization_assignments_url(current_organization), notice: 'Assignment was successfully destroyed.' else logger.warn "Unable to delete #{assignment}: '#{assignment.error_sentence}'" flash[:error] = "We were unable to delete the assignment" redirect_to :back end end |
#index ⇒ Object
GET /assignments
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/assignments_controller.rb', line 9 def index assignments = current_organization.assignments.to_a assignments.sort_by! do |a| [a.user_last_name, a.user_email].tap(&:compact!).first end memberships = current_organization.memberships.index_by(&:user_id) self.assigned_users = assignments.each_with_object(Hash.new(0)) do |assignment, hash| membership = memberships[assignment.user_id] hash[membership] = hash[membership] + 1 if membership.present? hash end end |
#new ⇒ Object
GET /assignments/new
30 31 |
# File 'app/controllers/assignments_controller.rb', line 30 def new end |
#show ⇒ Object
GET /assignments/1
26 27 |
# File 'app/controllers/assignments_controller.rb', line 26 def show end |