0

我不记得代码,如何以嵌套形式(通过简单形式)创建新对象。它类似于:“某物:new_object ...”

谢谢

4

2 回答 2

0

通常使用:

<%= 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,但请检查此线程:simple_form 中的嵌套属性返回质量分配错误

于 2012-11-24T05:33:07.697 回答
0

感谢保管箱,我找到了它..

您需要将此添加到您的 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
于 2012-11-25T23:38:03.337 回答