[英]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.