ActionView::Helpers::FormHelper
def text_field(object_name, method, options = {})

Description

Creates an <input> with type="text" for a model attribute.

Arguments

Changing a value updates the ERB and HTML.

object_name:user
method:name
options= {}
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <input type="text">, and ones this site considers rarely used, are not listed here.

Shared by …_field helpers

"Alice"
Sets value to the given value as is. Defaults to the object's value. If there is no object, or the value is nil, value is omitted.
true sets placeholder to the first of the following that is found:
  1. The helpers.placeholder.user.name translation
  2. If there is an object, the activerecord.attributes.user.name translation (what human_attribute_name returns)
  3. The attribute name run through humanize (Name)
A symbol (such as :home) looks for a translation specific to that value, in this order:
  1. The helpers.placeholder.user.name.home translation
  2. If there is an object, the activerecord.attributes."user/name".home translation
  3. The result of humanize (Home with an object, Name without)
A string is used as is. false does not look up a translation and gives placeholder="false".
30
Sets maxlength to the given value as is. Unless the :size option is given, also sets size to the same value.

Shared by form helpers

"q"
Replaces the generated name with the given value. nil omits name.
nil
Replaces the generated id with the given value. nil omits id.

Shared by all helpers

true adds disabled="disabled"; false omits it. The same goes for every HTML attribute in Rails' list (BOOLEAN_ATTRIBUTES), such as readonly, required and autofocus: any value other than false or nil adds it as attr="attr".
{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{controller: "tags", tags_suggestions_value: ["ruby", "rails"]}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
["section-user", "name"]
An array sets autocomplete to its elements joined with spaces.
/[a-z]+/i
A regular expression sets pattern to the part between / and /. Flags such as i are not included.
Any other options become HTML attributes of the <input type="text">; those with a nil value are left out.

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