ActionView::Helpers::FormHelper
def fields_for(record_name, record_object = nil, options = {}, &block)

Description

Outputs only the content of the block, without creating a <form>. The fields in the block are bound to model attributes.

Arguments

Changing a value updates the ERB and HTML.

The prefix of the name and id attributes of the fields in the block.
= nil
Uses the given object's values as the initial values of the fields. Defaults to the instance variable with the same name as record_name, if there is one.
options= {}
1
Inserted as an index into the name and id attributes of the fields in the block. nil adds [] instead of an index (comment[][body]).
"admin"
Prepended to the id attribute of the fields in the block. The name attribute does not change.
true omits id from the fields in the block and for from f.label. By default, id is added. Unlike form_with, config.action_view.form_with_generates_ids is not used.
true creates fields with no initial value for attributes the model does not have. By default, Rails tries to read such an attribute from the model and raises NoMethodError (try f.text_field :author_name in &block).
LabeledFormBuilder
Changes the class of the block's f (a FormBuilder). LabeledFormBuilder on this page overrides FormBuilder's text_field to add a label for the same attribute before the text_field.
fields_for outputs only the content of the block and creates no element of its own. As a result, options not listed here (such as class) do not become HTML attributes; they are passed to the block's form builder as settings.
&block= nil
Required. Omitting it raises LocalJumpError.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview

Interacting with the preview updates the form submission.

Form submission

Form data

namevalue
Request body

Content-Type:


              

params