2

I continue to get a undefined method error when attempting to get the ActiveAdmin form to use a selection box based of the keys for an enum properties for an object. Following the suggested method on stack overflow to configure active admin forms for enums seems to get me half way there although the engine aspect of my object seems to make the enum attribute through the NoMethodError exception.

 #/lib/book_store/admin/books
 if defined?(ActiveAdmin)
  ActiveAdmin.register  BookStore::Book, as: 'Book' do
    # customize your resource here
    form do |f|
      f.semantic_errors # shows errors on :base
      f.inputs   do
        f.input :cover_type, as: :select, collection:  BookStore::Book.cover_type.keys
      end
      f.actions         # adds the 'Submit' and 'Cancel' buttons
    end
    permit_params :name, :lead, :excerpt, :description, :price, :slug, :cover_type, :num_pages, :size, :cover_image, :author, :author_id, :category
  end
end



#app/models/book_store/book.rb
module BookStore
  class Book < ActiveRecord::Base
    belongs_to :author
    belongs_to :category
    enum cover_type: [:soft, :hard]
  end
end

gets the following error

undefined method `cover_type' for #<Class:0x007fe685217af0>

here is the full stack trace

Community
  • 1
  • 1
DogEatDog
  • 2,899
  • 2
  • 36
  • 65

2 Answers2

7

I think cover_type should be pluralized.

f.input :cover_type, as: :select, collection:  BookStore::Book.cover_types.keys
Eric C
  • 2,195
  • 1
  • 17
  • 23
Molle
  • 108
  • 6
2

Almost a related answer...

You can use enumerize gem and activeadmin addons to handle enumerations nicely.

Leantraxxx
  • 4,506
  • 3
  • 38
  • 56