There, form_for is
able to generate the rest of RESTful form parameters based on introspection
on the record, but to understand what it does we need to dig first into the
alternative generic usage it is based upon.

This also works for the methods in FormOptionHelper and DateHelper that are
designed to work with an object as base, like
FormOptionHelper#collection_select and DateHelper#datetime_select.

Resource-oriented style

As we said above, in addition to manually configuring the form_for
call, you can rely on automated resource identification, which will use the
conventions and named routes of that approach. This is the preferred way to
use form_for
nowadays.

Unobtrusive JavaScript

Specifying:

:remote=>true

in the options hash creates a form that will allow the unobtrusive
JavaScript drivers to modify its behaviour. The expected default behaviour
is an XMLHttpRequest in the background instead of the regular POST
arrangement, but ultimately the behaviour is the choice of the JavaScript
driver implementor. Even though it’s using JavaScript to serialize
the form elements, the form submission will work just like a regular
submission as viewed by the receiving side (all elements available in
params).

Customized form builders

You can also build forms using a customized FormBuilder class.
Subclass FormBuilder
and override or define some more helpers, then use your custom builder. For
example, let’s say you made a helper to automatically add labels to
form inputs.

If you need to get the object for the form inside a partial, and can’t
use the instance variable, use the #object method… This is particularly
useful when you’re dealing with single-table inheritance subclasses (e.g.
MyOtherClass inherits from MyClass) or when you are using the same partial
across different controllers.

Helper generates a div element with a hidden input inside. This is a
security feature of Rails called cross-site
request forgery protection and form helpers generate it for every form
whose action is not “get”.

If you want to add additional parameters to the form_for helper,
but still want to use one form for both your “create” and your
“update” actions, you can add the additional parameters to the :url
option, but you need to omit the :controller and :action keys.