2

I'm using the active_enum gem in my Rails 4 application. https://github.com/adzap/active_enum

gem 'active_enum'

In my model, I have an enumerate:

class Meeting < ActiveRecord::Base
  enumerate :participant_type do
    value 0 => 'Juniors'
    value 1 => 'Senior'
    value 2 => 'Administration'
  end
end

How can I use these values in a form select element?

I've tried the following but I get a runtime error:

= f.select :participant_type, Loan.participant_type

undefined method `participant_type' for #<Class:0x007f8803581050>
sergserg
  • 21,716
  • 41
  • 129
  • 182

1 Answers1

1

Make Participant type as a separate class that extends ActiveEnum::Base and try .to_select method.

= f.select :participant_type, ParticipantType.to_select, required: true

If it is Active Record Enum, try the below:

It is a plural participant_types as mentioned in the docs.

= f.select :participant_type, Meeting.participant_types, required: true
Raj
  • 22,346
  • 14
  • 99
  • 142
  • No, that's for baked in ActiveRecord::Enum's. I'm not using those in this case. I'm using `active_enum` a completely separate gem. :) – sergserg Jul 27 '14 at 13:15
  • there are few options - Make a separate class and use to_select, or use the form helpers as mentioned here https://github.com/adzap/active_enum#form-helpers – Raj Jul 27 '14 at 13:22