0

我正在尝试填充一个集合(@displayable_collection)以在我的表单中进行选择
(这是最终将进入@displayable_collection 的简化版本

这是我的代码......但它不工作......我做错了什么?

controller do
  before_filter :populate_collection, :only => [:new, :edit]

  private
  def populate_collection
    @displayable_collection = ArtItem.all.map{ |item| [item.to_s, "#{item.class}_#{item.id}"]}
  end
end

form do |f|
  f.inputs 'Details' do
    f.input :project
    f.input :name
  end

  f.inputs 'Display Items' do
    f.has_many :display_items do |item|
      item.input :displayable_combined_fields, :collection => @displayable_collection
      item.input :location, :input_html => {:selected => location.id}
      item.input :height
      item.input :width
      item.input :depth
    end
  end
  f.actions
end
4

1 回答 1

0

所以答案是您将实例变量引用为辅助方法。我知道这听起来很奇怪,但它确实有效。

记录在这里: https ://github.com/gregbell/active_admin/issues/2298

controller do
  before_filter :populate_collection, :only => [:new, :edit]

  private
  def populate_collection
    @displayable_collection = ArtItem.all.map{ |item| [item.to_s, "#{item.class}_#{item.id}"]}
  end
end

form do |f|
  f.inputs 'Details' do
    f.input :project
    f.input :name
  end

  f.inputs 'Display Items' do
    f.has_many :display_items do |item|
      item.input :displayable_combined_fields, :collection => displayable_collection
      item.input :location, :input_html => {:selected => location.id}
      item.input :height
      item.input :width
      item.input :depth
    end
  end
  f.actions
end
于 2013-06-24T20:41:43.063 回答