Michael Breen
2009-Mar-27  23:33 UTC
add :new_if_blank option to fields_for for nested associations
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2365-add-new_if_blank-option-to-fields_for-for-nested-associations
This patch will allow you to initialize any blank associations for  
your models that are using nested_attributes_for.
# for one-to-one association
form_for(@post) do |f|
   f.text_field(:title)
   f.fields_for(:author, :new_if_blank => true) do |af|
     af.text_field(:name)
   end
end
# for collection associations
# this will create 3 blank comments
form_for(@post) do |f|
   f.text_field(:title)
   f.fields_for(:comments, :new_if_blank => 3) do |cf|
     cf.text_field(:name)
   end
end
Thanks.
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---