0

I can't remember on the code, how to create new object in nested form (via Simple-form).. It was something like: "something :new_object ..."

Thanks

jirikolarik
  • 1,243
  • 1
  • 13
  • 25

2 Answers2

0

Normallyc use:

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

But you can use simple_fields_for, like this:

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

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

It is initially using form_for, but check this thread: nested attributes in simple_form returns mass assignment error

Community
  • 1
  • 1
pablomarti
  • 2,087
  • 2
  • 22
  • 35
  • I have this, but I need to create new empty :post. I had button "Create new empty post for user". Something like link_to :new_object, but I forgot how exactly is it – jirikolarik Nov 24 '12 at 09:49
0

Thanks to dropbox, I found it..

You need add this to your javascript (in CoffeScript)

#= require jquery_nested_form

And that's the form (in 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
jirikolarik
  • 1,243
  • 1
  • 13
  • 25