I'm using ActiveAdmin and Formtastic.
I have an invoice form that has a drop down menu of shipments.
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
I only want to display the select menu for shipments if the form is a New Invoice form.
I do not want to display the shipments drop down select menu if the form is an edit form. So if the form is an edit form, it won't be changed.
I was thinking about doing something like
if params[:action] != 'edit'
f.input :shipment_id, :label => "Shipment", :as => :select...
end
but I get a DSL error.
try
form do |f|
f.inputs "Shipment Details" do
if f.object.new_record?
f.input :shipment_id, :label => "Shipment", :as => :select...
end
...
end
end
Question (partially) answered earlier here: Accessing object of form in formtastic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With