我正在尝试填充一个集合(@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
答案 0 :(得分: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