2012-03-14 36 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