Skip to content

Add and document ActionText without_layout reader and writer attributes

Created by: mrj

If a site follows an ActionText editing form with a preview form prior to record creation, the natural way to set the editor content in the preview form is something like:

<%= hidden_field :message, :content %>

This however does a to_s, which includes the content with the "trix-content" div layout wrapping. This wrapping gets saved, and the final rendering with layout has a double wrapping.

A solution is to instead use

<%= hidden_field_tag 'message[content]', @message.content.to_trix_html %>

but a cleaner solution would be to provide a non-wrapped accessor like

<%= hidden_field :message, :content_without_layout %>

This PR does this. It also fixes the incorrect documentation of has_rich_text that shows to_s as producing HTML without layout, documents the without_layout variant, and adds a sentence suggesting when each should be used.

Merge request reports