From 6d03d80a31f0b86ea3f01f7d4f025147757039be Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 16 Apr 2024 19:46:00 -0500 Subject: [PATCH] Corrected an error with Form Roles vs Rolify Roles. Forms view for create and edit now show the correct roles that should be assigned. --- app/controllers/forms_controller.rb | 4 ++-- app/models/form.rb | 6 ++++++ app/views/forms/_form.html.erb | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index 01a659e..da2a3e7 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -25,7 +25,7 @@ class FormsController < ApplicationController end def update - if @form.update(form_params) + if @form.update(form_params[:id]) redirect_to @form, notice: 'Form was successfully updated.' else render :edit @@ -50,7 +50,7 @@ class FormsController < ApplicationController end def form_params - params.require(:form).permit(:name, :required, :program, role_ids: []) + params.require(:form).permit(:name, :required, :program, form_role_ids: []) end diff --git a/app/models/form.rb b/app/models/form.rb index fd7f138..940b155 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -11,6 +11,12 @@ class Form < ApplicationRecord after_save :update_onboarding_items private + + def form_role_ids=(ids) + self.form_roles = ids.reject(&:blank?).map { |id| Role.find(id) } + end + + def update_onboarding_items roles.each do |role| diff --git a/app/views/forms/_form.html.erb b/app/views/forms/_form.html.erb index 79a9e67..77493ee 100644 --- a/app/views/forms/_form.html.erb +++ b/app/views/forms/_form.html.erb @@ -26,8 +26,8 @@
- <%= f.label :role_ids, 'Roles', class: 'form-label' %> - <%= f.collection_select :role_ids, Role.all, :id, :name, {}, { multiple: true, class: "form-control" } %> + <%= f.label :form_role_ids, 'Roles', class: 'form-label' %> + <%= f.collection_select :form_role_ids, FormRole.all, :id, :name, {}, { multiple: true, class: "form-control" } %>