render_nested_form Helper

Die in Rails 2.3 eingeführten Nested Forms haben mir am Anfang sehr viele Kopfschmerzen bereitet und tun dies immer mal wieder.

Dank schorsch vom SalesKing muss ich mir um diese Dinge keine Sorgen mehr machen.
Sein render_nested_form Helper übernimmt alles und hat ein paar sehr nette Options.

# Options are:
# * <tt>:new</tt> - specify a certain number of new elements to be added to the form. Useful for displaying a few blank elements at the bottom.
# * <tt>:name</tt> - override the name of the association, both for the field names, and the name of the partial
# * <tt>:partial</tt> - specify the name of the partial in which the form is located.
# * <tt>:fields_for</tt> - specify additional options for the fields_for_associated call
# * <tt>:locals</tt> - specify additional variables to be passed along to the partial
# * <tt>:render</tt> - specify additional options to be passed along to the render :partial call
# * <tt>:skip</tt> - array of elements which will be skipped, usefull if you already rendered a partial in the same form with parts of the data. eg. obj.addresses, render the firt address on top of form, render all the other addresses at the bottom
 
f.render_nested_form(@project.tasks, :new => 3, :partial=>'some_partial', :locals=>..)

Update:
Ich hab den Helper geforked und die Option :as hinzugefügt. Damit kann man den Namen der lokalen Variable definieren, wenn man den Partial z.B. für unterschiedliche Objekte und Attribute nutzt (bei mir ist das ein Upload Form).
Hier findet ihr den Fork.

Ähnliche Posts:
» MCV Ruby on Rails – was gehört wohin?
» FINALLY! RailsICalendar ical ics publish with ruby on rails

0 Responses to “render_nested_form Helper”


  • No Comments

Leave a Reply