我使用Cocoon和SimpleForm进行新订单,它将有多个OrderItems。
我已经像这样安装了宝石:
{
"fields" : ["Events.Count","Events.Value_Aggregations.Count"]
"query": {
"filtered": {
"query": {
"match": { "Domain": "abc.com" }
},
"filter": {
"nested": {
"path": "Events",
"query": {
"match": { "Events.Name": "visit" }
},
}
}
}
}
}
并且还添加到application.js:
gem "cocoon"
模型的配置如下:
//= require cocoon
_form.html.slim for Orders是:
class Order < ActiveRecord::Base
#Associations
has_many :order_items
accepts_nested_attributes_for :order_items, reject_if: :all_blank, allow_destroy: true
end
class OrderItem < ActiveRecord::Base
#Associations
belongs_to :order
belongs_to :item
end
和部分_order_items_fields.html.slim是:
= simple_form_for(@order) do |f|
= f.error_notification
.row
.col-md-6
.form-inputs
= f.association :branch
= f.association :client
.col-md-6
= f.simple_fields_for :order_items do |order_item|
= render 'order_item_fields', f: order_item
.links
= link_to_add_association 'add order_item', f, :order_items
.form-actions
= f.button :submit
当我运行orders / new时,除了应该由cocoon显示的字段外,显示所有字段。
我已经通过github页面上的说明完成了所有工作。
问题是什么?
我还检查了并且正在加载cocoon JS文件。
答案 0 :(得分:1)
我对HAML了解不多,但我认为您需要将.links
与= f.simple_fields_for :order_items do |order_item|
对齐,因为HAML依赖于空格。
使用来自Cocoon github链接的this simple form example
答案 1 :(得分:0)
您的表单为空,因为您的字段应嵌套在simple_form
= simple_form_for(@order) do |f|
= f.error_notification
.row
.col-md-6
.form-inputs
= f.association :branch
= f.association :client