2

好的,我认为这在 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包含invoiceI 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

4

1 回答 1

0

您可以做什么:使货件选择列表的集合显示“当前”发票所连接的客户。因此,对于集合,您可以加入 Customer 模型,如下所示:

f.input :shipment_id, :label => "Shipment", :as => :select, 
        :collection => 
          Shipment.
              joins(:customer).
              order('shipments.file_number').
              select("shipments.id, shipments.file_number || ' ' ||  customers.your_beautiful_customer_attribute as concatted").
              map{|v| [v.concatted, v.id] }

希望能帮助到你。

于 2012-12-07T15:18:42.337 回答