Вопрос

I have a Product model, set up with 4 children using STI.

My active_admin form looks like this:

form do |f|
    f.inputs do
        f.input :type, collection: Product.select_options
        f.input :title
        etc.
    end
    f.buttons
end

Relevant code from parent model:

  def self.select_options
    descendants.map{ |c| c.to_s }.sort
  end

Initializer:

if Rails.env.development?
  %w[product ring necklace bracelet earring].each do |c|
    require_dependency File.join("app","models","#{c}.rb")
  end
end

It all works fine and when I'm in the console I can do Product.select_options and it prints them out.

Why won't active_admin pick them up? It simply gives me a blank drop down with a tick inside it.

Thanks

Это было полезно?

Решение

You missed as: :select

Replace
f.input :type, collection: Product.select_options
With
f.input :type, as: :select, collection: Product.select_options
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top