Co2 Co2 - 6 months ago 17
Ruby Question

RoR Enum "Unable to autoload constant" error

I am getting a basic enum error in active admin:


Unable to autoload constant School_user


I have defined the enums in the model:

class SchoolUser < ActiveRecord::Base
belongs_to :user
has_one :school

enum user_type: [:school, :student, :guardian, :teacher]

end


And in admin/school_user.rb I am trying to get the dropdown list:

ActiveAdmin.register SchoolUser do

permit_params [:user_type]

form do |f|
f.inputs "School_user" do
f.input :user_type, :as => :select, :collection => School_user::user_type.keys
end
f.actions
end

end


user_type is an integer.

I don't know what i'm doing wrong here but I bet it's a simple oversight. Any help?

Answer

Unable to autoload constant School_user

I believe the error is in the below line

f.input :user_type, :as => :select, :collection => School_user::user_type.keys

where School_user should be SchoolUser

f.input :user_type, :as => :select, :collection => SchoolUser::user_types.keys
Comments