Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 嵌套形式的动态选择器_Ruby On Rails 3_Activeadmin_Formtastic - Fatal编程技术网

Ruby on rails 3 嵌套形式的动态选择器

Ruby on rails 3 嵌套形式的动态选择器,ruby-on-rails-3,activeadmin,formtastic,Ruby On Rails 3,Activeadmin,Formtastic,我需要一个表格,以便能够显示一个选择的基础上另一个 我有以下数据库模式: order <-->> line_items <<-->> product <-->> campaign <br> order <<--> customer 我需要在这里显示一个活动选择器,它过滤一个产品选择器,根据嵌套表单中的活动显示产品。(类似于具有产品类别过滤器) 你知道怎么做吗 谢谢,一旦您的表单达到这种复杂程度,我建议您用

我需要一个表格,以便能够显示一个选择的基础上另一个

我有以下数据库模式:

order <-->> line_items <<-->> product <-->> campaign <br>
order <<--> customer
我需要在这里显示一个活动选择器,它过滤一个产品选择器,根据嵌套表单中的活动显示产品。(类似于具有产品类别过滤器)

你知道怎么做吗


谢谢,

一旦您的表单达到这种复杂程度,我建议您用自定义模板替换它,很遗憾


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

感谢@SimonHildebrandt对Formtastic的正面限制。我完全重写了我的表格的一部分,让它像以前一样工作。然而,我有一个困难的时间与js部分。有什么提示或代码让我走上正确的道路吗?
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