2012-03-14 41 views
0

在active_admin: 一些代码不工作是这样的:不能在数组中工作?

form do |f| 
f.inputs "title" do 
    %w(AreaGroupId DescriptionFlags Dispel Mechanic modalNextSpell).each do |ele| 
    f.input ele 
    end 
    end 
end 

当我写其他格式是这样的:

form do |f| 
    f.inputs "title" do 
    f.input AreaGroupId 
    f.input DescriptionFlags 
    f.input Dispel 
    f.input Mechanic 
    f.input modalNextSpell 
    end 
end 

所以可以运行

为什么呢?有问题 ?

回答

1

这是因为Formtastic如何工作,给f.inputs的块必须返回最后一个输入。如果您想快速修复,请尝试以下操作:

form do |f| 
f.inputs "title" do 
    %w(AreaGroupId DescriptionFlags Dispel Mechanic modalNextSpell).map do |ele| 
    f.input ele 
    end.last 
    end 
end 
+1

是的。它修复了谢谢! – lioooo 2012-03-30 10:12:23