Search code examples
ruby-on-railsenumsactiveadminenumerate

Rails activeadmin with enumerateit


I have a rails project with active admin that has a model with a field that is a string with enumerate_it:

class PrivacyType < EnumerateIt::Base
  associate_values(
    private: [1, 'Private'],
    public: [2, 'Public'] )
end

In the form everything work as expected and there's a dropdown list with the options privateand public:

form do |f|
  f.inputs 'Details' do
    f.input :privacy_type, as: :select, collection: PrivacyType.to_a
  end
end

Bit in the index, it shows the numbers 1 and 2 instead of the text. It is like this:

index do
  columns :privacy_type
end

What do I need to do to have the text private or public written instead of the numbers?

Thanks


Solution

  • This should work

    index do
      columns :privacy_type do |record|
        PrivacyType.value_for(record.privacy_type)
      end
    end