'Does the devise/devise_invitable gem support Rails collection_check_boxes?

I have a simple feature where I as an admin have to invite users to my application. I am achieving this with Devise Invitable. However, in the invite flow, I need to be able to add roles to a user and then send the invite. Devise invitable has an example to achieve this but my situation is a little different. The example provided shows roles as an enum on the user.rb model where mine is an association. Here is the relevant code:

class User < ApplicationRecord
   has_and_belongs_to_many :roles
end

class Role < ApplicationRecord
  has_and_belongs_to_many :users


  def woot
    "HELLO WORLD TEST TEST"
  end
end

The problem even before attempting to invite a user is that no matter how I try to setup a form with this has_and_belongs_to_many association, the form simply will not render and I'm not sure as to why.

Essentially, I want to have a group of checkboxes where when I click them, it will assign a user the needed roles. I chose to use collection_check_boxes Collection Check box to do so. However this simple form doesn't render. What can I be doing incorrectly?

= form_for(resource, as: resource_name, url: invitation_path(resource_name), html: { method: :post }) do |f|
  = render "devise/shared/error_messages", resource: resource

  = f.collection_check_boxes(:role_ids, Role.all, :id, :woot)
 
  - resource.class.invite_key_fields.each do |field|
    .field
      = f.label field
      %br/
      = f.text_field field, class:'uk-input uk-form-small uk-form-width-large', required: true
    
  .actions
    %br/
    = f.submit t("devise.invitations.new.submit_button"), class: 'uk-button uk-button-big uk-button-primary'
  

Additionaly, I've tried basic examples including options_for_select just to get it to work but it still doesn't. Lastly, I followed the documentation for collection_check_boxes to a tee and still nothing. What could I be doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source