Read more

How to change the order of nested forms being rendered (especially blank forms)

Deleted user #6
October 12, 2011Software engineer

Generally for nested forms, a blank form is placed below all other existing object forms. If you would like to change the position of the blank form(s) you can reorder the object's one-to-many association. For example you can put the blank form on top with the following snippet:

actors = movie.actors
actors.build
actors.unshift(actors.pop(1)) # won't work with Rails 4+
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Because build_for_form creates new objects and appends them to the one-to-many association collection object you only have to reorder the collection objects.

Sorting with Rails 3+

= form.fields_for :children, @parent.children.sort_by(&:name) do |fieldsform|
  …
Posted to makandra dev (2011-10-12 09:27)