2016-06-12 58 views
0

我想在窗體中使用多個嵌套的屬性,雖然只有第一組屬性似乎出現。軌道項目上的紅寶石內的多個嵌套窗體

下面是HAML模板

.mdl-cell.mdl-cell--10-col.mdl-cell--1-offset 
    %h3.mdl-typography--display-1= t('.account_title') 
    = form.fields_for :address do |address_fields| 
    .mdl-grid 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--6-col 
     = address_fields.text_field :first_name, class: 'mdl-textfield__input' 
     = address_fields.label :first_name, class: 'mdl-textfield__label' 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--6-col 
     = address_fields.text_field :last_name, class: 'mdl-textfield__input' 
     = address_fields.label :last_name, class: 'mdl-textfield__label' 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--6-col 
     = form.text_field :name, class: 'mdl-textfield__input' 
     = form.label :name, class: 'mdl-textfield__label' 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--6-col 
     = form.email_field :email, class: 'mdl-textfield__input' 
     = form.label :email, class: 'mdl-textfield__label' 
    %h3.mdl-typography--display-1= t('.bank_title') 
    = form.fields_for :account do |account_fields| 
    .mdl-grid 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--6-col 
     = account_fields.text_field :bsb, class: 'mdl-textfield__input' 
     = account_fields.label :bsb, class: 'mdl-textfield__label' 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--6-col 
     = account_fields.text_field :account_number, class: 'mdl-textfield__input' 
     = account_fields.label :account_number, class: 'mdl-textfield__label' 
     .mdl-textfield.mdl-js-textfield.mdl-textfield--floating-label.mdl-cell.mdl-cell--12-col 
     = account_fields.text_field :account_name, class: 'mdl-textfield__input' 
     = account_fields.label :account_name, class: 'mdl-textfield__label' 

定義在型號

accepts_nested_attributes_for :address, reject_if: proc { |attributes| attributes['address1'].blank? } 
    accepts_nested_attributes_for :trading_hours 
    accepts_nested_attributes_for :phones, :reject_if => lambda { |t| (t['display_number'].gsub(/\D+/, '').blank?) } 
    accepts_nested_attributes_for :account 
+0

你能顯示從你的rails服務器日誌傳遞的參數嗎? – Kumar

回答

-1

在你需要建立各自的附加屬性的形式(這是一種新形式,是家長,我相信你可以在控制器下做這個def新的...)

def new 
    @parent.address.build 
    @parent.trading_hours.build 
    @parent.phones.build 
    @parent.account.build 
end 

如果你沒有嘗試g做一個新的表單讓我知道並更新問題

+0

這似乎是找到的,但根據魯米姬告訴我的文檔,違背了Rails的方式 –

+0

如果你這麼說,大聲笑好吧!如果在對象上沒有構建屬性,屬性將不會顯示。 – Dave

+0

該代碼不應該在控制器中,因爲只應調用1個方法。這不是最佳實踐,它違背了FAT模型,皮包骨頭控制器 –