Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The form_for helper method sets up the entire form, creating the HTML form element but also providing context for all of the fields in the
form. The form_for method is a bit
sneaky, too. Both the new.html.erb
view and the edit.html.erb view use
form_for the same way:
<%= form_for(@person) do |f| %> ... <% end %>
However, the generated form
element looks very different, depending on what exactly is in @person. If @person is just an empty object structure,
form_for will work on the assumption
that this is to create a new object. If @person actually contains data, however,
form_for will assume that its form is
editing that object and create a different-looking form element, plus a hidden field to enable
Rails’ REST capabilities.