FormHelper, FormTagHelper, and FormOptionsHelper
These three classes of helper methods offer different approaches
to building forms and some different pieces for creating forms. Much of
the time you’ll want to use either FormHelper or FormTagHelper, but you might mix FormOptionsHelper with either of the other
two.
The FormHelper methods create form fields bound to particular attributes
of ActiveRecord objects. They are
easiest to use within a form_for
method that sets their context, as described in Chapter 6. If you don’t like
that approach, you can supply an object and attribute name as the first
two parameters when calling them. (The documentation for each method
shows the parameter approach.)
check_boxCreates a checkbox field bound to an attribute from the object specified in
form_foror in the parameters. (It also creates a hidden field bound to the same attribute for use if the checkbox isn’t checked.)fields_forfields_foris likeform_for, except that it doesn’t create the actualformtags.file_fieldCreates a file upload field bound to an attribute from the object specified in
form_foror in the parameters. (You’ll need to modify theform_forcall as described in Chapter 8 to use this method.)form_forCreates a
formelement and sets the context for the other helper methods inFormHelper.hidden_fieldCreates a hidden field bound to an attribute from the object specified in
form_foror in the parameters.labelCreates a label for a field created with the other methods of
FormHelper ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access