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_box

Creates a checkbox field bound to an attribute from the object specified in form_for or in the parameters. (It also creates a hidden field bound to the same attribute for use if the checkbox isn’t checked.)

fields_for

fields_for is like form_for, except that it doesn’t create the actual form tags.

file_field

Creates a file upload field bound to an attribute from the object specified in form_for or in the parameters. (You’ll need to modify the form_for call as described in Chapter 8 to use this method.)

form_for

Creates a form element and sets the context for the other helper methods in FormHelper.

hidden_field

Creates a hidden field bound to an attribute from the object specified in form_for or in the parameters.

label

Creates a label for a field created with the other methods of ...

Get Learning Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.