我對新訂單使用Cocoon和SimpleForm,它將有多個OrderItems。Rails - Cocoon - 簡單窗體 - 不渲染
我已經安裝了寶石,像這樣:
gem "cocoon"
,並添加到application.js中:
//= require cocoon
型號配置,如下所示:
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
_form。訂單的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
和部分_order_items_fields.html.slim是:
.nested_fields
= f.input :item_id
= f.input :dicount_percentage
= f.input :fulfilment_type
= f.input :promised_delivery_date
= f.input :actual_delivery_date
= f.input :notes
= link_to_remove_association "remove order item", f
當我運行命令/新,顯示除應當由繭顯示的那些所有的領域。
我已經完成了github頁面上的說明。
問題是什麼?
我也檢查過,繭JS文件正在加載。
我多麼粗心!非常感謝您發現! –