Selecting a Role from Rolify while using ActiveAdmin

1.1k views Asked by At

Using Rails 4 with ActiveAdmin 5 coupled with CanCan and Rolify, I want to be able to select (via list of checkboxes or something) the roles which will apply to each user when editing or creating new users via the Active Admin Interface.

This post How to use ActiveAdmin on models using has_many through association? sort of shows the way to build the forms. Although I receive the error:

undefined method `new_record?' for nil:NilClass

This seems to occur when simply accessing the .has_many property when doing form do |f|

f.has_many :roles do |app_f|
  #app_f.inputs "Roles" do
    #if !app_f.object.nil?
      # show the destroy checkbox only if it is an existing appointment
      # else, there's already dynamic JS to add / remove new appointments
   #app_f.input :_destroy, :as => :boolean, :label => "Destroy?"
  #row app_f.role.name
  #end

  #  app_f.input :roles # it should automatically generate a drop-down select to choose from your existing patients

  #end
end
1

There are 1 answers

0
DogEatDog On BEST ANSWER

I found that taking a different route to access the roles works much better via the f.input

Here is the working code:

  form do |f|
    f.inputs "Admin Details" do
      f.input :email
      f.input :first_name
      f.input :last_name
      f.input :alias
      f.input :bio
      f.input :password
      f.input :password_confirmation
      f.input :roles, :as => :check_boxes
    end
    f.actions
  end