2012-11-23 74 views

回答

0

多虧了Dropbox的,我發現它..

您需要添加到您的JavaScript(在CoffeScript)

#= require jquery_nested_form 

這就是今天的形式(HAML)

= simple_nested_form_for @variable do |f| 
    = f.input :code 
    // Link to create new empty object  
    = f.simple_fields_for :nested_attributes do |s| 
    = f.link_to_add "Add new", :nested_attributes 
    = s.input :name 
    = s.input :locale 
    // Link to remove 
    = s.link_to_remove 'Remove' 
    = f.button :submit 
0

Normallyc使用:

<%= f.fields_for :object do |builder| %> 

但是你可以使用simple_fields_for,像這樣:

form_for @user do |f| 
    f.simple_fields_for :posts do |posts_form| 
    # Here you have all simple_form methods available 
    posts_form.input :title 
    end 
end 

參考:http://simple-form.plataformatec.com.br/#usage/extra-helpers

它最初使用的form_for,但檢查這個線程:nested attributes in simple_form returns mass assignment error

+0

我有這個,但我需要創建新的空:職位。我有按鈕「爲用戶創建新的空白帖子」。像link_to:new_object,但我忘了它到底是什麼 – jirikolarik