ActionView::Helpers::FormHelper

Alias: rich_text_area

def rich_textarea(object_name, method, options = {}, &block)

Description

Creates an Action Text editor (<trix-editor>) for a model attribute, and a hidden <input> that holds its content.

Arguments

Changing a value updates the ERB and HTML.

object_name:article
method:body
options= {}
"<p>Hello</p>"
Used as the value attribute of the hidden <input>, which Trix reads as the initial content of the editor. Defaults to the object's value converted to HTML.
"body_input"
Used as the id attribute of the hidden <input> and the input attribute of <trix-editor>. Trix uses this id to find the <input> to write the content into. Defaults to a sequential value such as trix_input_1; the counter keeps increasing for the life of the server process (this site resets it to 1 on every render). With an object, the id is built with dom_id.
"other_form"
Added only to the hidden <input>, not to <trix-editor>.
{direct_upload_url: "/uploads"}
Rails adds data-direct-upload-url and data-blob-url-template, set to the Active Storage upload URL and the template for file URLs. Giving the same keys in :data overrides them. Other keys are added as data-* attributes as is.
"class_xxx"
Replaces the default trix-content. Without trix-content, the parts of the Trix CSS that style the content (headings, lists, etc.) no longer apply.
Common options

Rails handles these the same way in every helper. <trix-editor> is a custom element defined by Trix, so HTML attributes that apply only to <input> (such as pattern) are left out here.

Shared with …_field helpers and others

true sets placeholder to the first of the following that is found:
  1. The helpers.placeholder.article.body translation
  2. If there is an object, the activerecord.attributes.article.body translation (what human_attribute_name returns)
  3. The attribute name run through humanize (Body)
A symbol (such as :home) looks for a translation specific to that value, in this order:
  1. The helpers.placeholder.article.body.home translation
  2. If there is an object, the activerecord.attributes."article/body".home translation
  3. The result of humanize (Home with an object, Body without)
A string is used as is. false does not look up a translation and gives placeholder="false".

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".
{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.
Any other options become HTML attributes of the <trix-editor>; those with a nil value are left out.
&block= nil

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


              
This site does not upload images or files. An image pasted into the editor is shown, but its upload never finishes, so Trix does not write it into the hidden <input>, and it does not end up in the form data either.
In an app that uses Action Text, the file is uploaded as soon as it is pasted, separately from the form submission.