Corrected an error with Form Roles vs Rolify Roles. Forms view for create and edit now show the correct roles that should be assigned.

This commit is contained in:
Ben 2024-04-16 19:46:00 -05:00
parent bb9c354146
commit 6d03d80a31
3 changed files with 10 additions and 4 deletions

View File

@ -25,7 +25,7 @@ class FormsController < ApplicationController
end end
def update def update
if @form.update(form_params) if @form.update(form_params[:id])
redirect_to @form, notice: 'Form was successfully updated.' redirect_to @form, notice: 'Form was successfully updated.'
else else
render :edit render :edit
@ -50,7 +50,7 @@ class FormsController < ApplicationController
end end
def form_params def form_params
params.require(:form).permit(:name, :required, :program, role_ids: []) params.require(:form).permit(:name, :required, :program, form_role_ids: [])
end end

View File

@ -11,6 +11,12 @@ class Form < ApplicationRecord
after_save :update_onboarding_items after_save :update_onboarding_items
private private
def form_role_ids=(ids)
self.form_roles = ids.reject(&:blank?).map { |id| Role.find(id) }
end
def update_onboarding_items def update_onboarding_items
roles.each do |role| roles.each do |role|

View File

@ -26,8 +26,8 @@
</div> </div>
<div class="mb-3"> <div class="mb-3">
<%= f.label :role_ids, 'Roles', class: 'form-label' %> <%= f.label :form_role_ids, 'Roles', class: 'form-label' %>
<%= f.collection_select :role_ids, Role.all, :id, :name, {}, { multiple: true, class: "form-control" } %> <%= f.collection_select :form_role_ids, FormRole.all, :id, :name, {}, { multiple: true, class: "form-control" } %>
</div> </div>
<div class="actions"> <div class="actions">