簡體   English   中英

在ActiveAdmin中的before_filter中填充表單的集合

[英]Populate a collection for a form in a before_filter in ActiveAdmin

我正在嘗試填充要在我的表單中選擇的集合(@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

因此,答案是您將實例變量作為輔助方法進行引用。 我知道這聽起來很奇怪,但是可以。

記錄在這里: 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM