<div><br></div><div>Nested inside your form you can do something like the following, </div><div><br></div><div><font face="'courier new', monospace">- @widget.dookickies.sorted.each do |doohickey|</font></div><div>
<font face="'courier new', monospace"> = f.fields_for :doohickies, doohickey do |dform|</font></div><div><font face="'courier new', monospace"> = dform.text_field :title</font></div><div><br></div><div>
<br></div><br><br><div class="gmail_quote">On Tue, Apr 10, 2012 at 1:43 PM, Chris Adams <span dir="ltr"><<a href="mailto:mail@chrisadams.me.uk">mail@chrisadams.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><div>Hi chaps, </div><div><br></div><div>I'm working with a Rails 3.2 app at the moment, and I'm building a nested form using the idiomatic `form_for` rails syntax, so the code looks a bit like:</div>
<div><br></div><div> <%= form_for @widget do |f| %></div><div><br></div><div> <%= f.text_field :content %></div><div><br></div><div> <% fields_for :doohickey do | builder | %></div><div><br>
</div><div> <%= builder.text_field :title %></div><div> <%= builder.text_field :amount %></div><div><br></div><div> <% end %></div><div><br></div><div> <%= f.submit %></div>
<div><br></div><div> <% end %></div><div><br></div><div>Now assume :widget has_many :doohickeys, but doohickeys have a number of other properties you might want to sort them by.</div><div><br></div><div>I'd like to have more control over the order of how the children on a given object are displayed in a form when it's first generated, so I can order the children by colour, for example, or something similar. </div>
<div><br></div><div>A bit like:</div><div><br></div><div> <%= form_for @widget do |f| %></div><div><br></div><div> <%= f.text_field :content %></div><div><br></div><div> <% (fields_for :doohickey).some_custom_ordering_or_filtering_scope do | builder | %></div>
<div><br></div><div> <%= builder.text_field :title %></div><div> <%= builder.text_field :amount %></div><div><br></div><div> <% end %></div><div><br></div><div> <%= f.submit %></div>
<div><br></div><div> <% end %></div><div><br></div><div>Anyone know if there are any libraries that let me make selective queries like this for displaying in a nested form? </div><div><br></div><div>I haven't been working with rails long enough to be know how Rails 3 handles nested models in forms too well, yet, and right now my only options seem to be resort to using javascript in the client to rearrange the dom, or veering away from the handy `form_for` syntax that I've got used to everywhere else in app.</div>
<div><br></div><div>Suggestions?</div><div><br></div><div>Thanks,</div></div></div></blockquote></div>