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 に答える