0

我需要一种表格,以便能够基于另一个显示一个选择。

我有以下数据库架构:

order <-->> line_items <<-->> product <-->> campaign <br>
order <<--> customer

我有以下表格:

form do |f|
    f.inputs I18n.t("New Order") do
      f.input :customer, :collection => Customer.where(:id => order.customer_id).map{ |customer|     [customer. FirstName + ' ' + customer.LastName, customer.id] }
    end

      f.has_many :line_items do |app_f|
        app_f.input :quantity

        #some code that show campaign to filter :product_id

        app_f.input :product_id, :as => :select, :collection => Product.all.map{ |product| [product.name, product.id] }
          if app_f.object.id
            app_f.input :_destroy, :as => :boolean, :label => I18n.t("Delete")
          end
          app_f.form_buffers.last # to avoid bug with nil possibly being returned from the above
      end
    end
  f.actions
 end

我需要在这里显示一个活动选择器,该选择器过滤产品选择器以根据嵌套形式的活动显示产品。(类似于拥有产品类别过滤器)

知道该怎么做吗?

谢谢,

4

1 回答 1

0

一旦您的表单达到这种复杂程度,我建议您用自定义模板替换它 -不幸的是, Formtastic 只能让您到目前为止

在自定义表单中,您可以使用 jQuery 设置产品选择中的选项以反映活动的正确值 - 甚至可以将产品选择放到一个部分中,并在活动选择更改时通过 ajax 重新加载它。

于 2013-06-12T01:26:09.637 回答