好的,我认为这在 ActiveAdmin 上会很棘手。
如果为某个客户创建了发票,我需要发出弹出警告(我可能会使用 jQuery)。如果发票表格有一个可供客户选择的菜单,这将很容易,但这不是我的设置。相反,这是它的工作方式:
Shipment has_one Invoice
Shipment belongs_to Customer
(the New Shipment form has a select menu for customer)
Invoice belongs_to Shipment
所以在我的新发票表格中,我有一个发货选择菜单。找出发票属于哪个客户,如果i
包含invoice
I do的实例i.shipment.customer
。
# this is a snippet of my New Invoice form
form do |f|
f.inputs "Shipment Details" do
f.input :shipment_id, :label => "Shipment", :as => :select, :collection => Shipment.find(:all, :order => "file_number", :select => "id, file_number").map{|v| [v.file_number, v.id] }
f.input :issued_at, :label => "Date", :as => :datepicker
f.input :accounting_month, :label => "Accounting month", :as => :datepicker
end
在新发票表单中:如何从货件选择菜单中获取货件所属的客户。
例如,用户选择 Shipment #1231。如果货件属于 customer_id 5,则显示 jQuery 警报。
(我已经知道如何在 ActiveAdmin 中包含一个 javascript 文件:Active Admin: Include Javascript)