Reputation: 3594
I have a form that has some nested fields - ie. User accepts_nested_attributes_for Class.
Class has an end_date datetime field.
I'd like to order the classes by end_date in the editing form. The form has something like this:
<%= f.fields_for :classes do |builder| %>
<%= render "class_fields", {:f => builder} %>
<% end %>
Obviously, they come out in order of the created_at field.
How can I modify this to order them by an arbitrary field?
Upvotes: 0
Views: 879
Reputation: 4296
If you always want classes sorted that way, you can add an :order option to your association. If not, fields_for takes a second argument that's the record(s) to display, so you can pass in your list in whatever order you want.
Upvotes: 1