1

我有一个产品模型,使用 STI 设置了 4 个孩子。

我的 active_admin 表单如下所示:

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

父模型的相关代码:

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

初始化器:

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

一切正常,当我在控制台中时,我可以执行 Product.select_options 并将它们打印出来。

为什么 active_admin 不接他们?它只是给了我一个空白下拉列表,里面有一个勾号。

谢谢

4

1 回答 1

0

你错过了::选择

代替
f.input :type, collection: Product.select_options
f.input :type, as: :select, collection: Product.select_options
于 2013-06-27T10:52:55.597 回答