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
I think cover_type should be pluralized.
f.input :cover_type, as: :select, collection: BookStore::Book.cover_types.keys
Almost a related answer...
You can use enumerize gem and activeadmin addons to handle enumerations nicely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With