我正在使用 ActiveAdmin 和 Formtastic。
我有一张发票表格,其中包含发货下拉菜单。
form do |f|
f.inputs "Shipment Details" do
f.input :shipment_id, :label => "Shipment", :as => :select, :collection => Shipment.find(invoiceless_shipments, :order => "file_number", :select => "id, file_number").map{|v| [v.file_number, v.id] }
f.input :issued_at, :label => "Date", :as => :datepicker
... more fields ...
end
如果表单是新发票表单,我只想显示发货的选择菜单。
如果表单是编辑表单,我不想显示发货下拉选择菜单。因此,如果表单是编辑表单,则不会更改。
我正在考虑做类似的事情
if params[:action] != 'edit'
f.input :shipment_id, :label => "Shipment", :as => :select...
end
但我收到 DSL 错误。
最佳答案
尝试
form do |f|
f.inputs "Shipment Details" do
if f.object.new_record?
f.input :shipment_id, :label => "Shipment", :as => :select...
end
...
end
end
问题(部分)在此之前得到回答:Accessing object of form in formtastic
关于ruby-on-rails - Rails 3. 使用 Formtastic 有条件地显示字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8704039/