2015-11-17 90 views
1

我對新訂單使用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文件正在加載。

回答

1

下一層,我不知道很多關於HAML,但我相信,你需要排隊.links= f.simple_fields_for :order_items do |order_item|因爲HAML是空白依賴。

使用this simple form example從繭github上

+0

我多麼粗心!非常感謝您發現! –

0

你的表格是空的,因爲你的領域應該simple_form

= simple_form_for(@order) do |f| 
    = f.error_notification 
    .row 
    .col-md-6 
     .form-inputs 
     = f.association :branch 
     = f.association :client 
+0

道歉,他們已經嵌套鏈接,我現在已經糾正了問題。現在一切都好嗎? –