method
has_rich_text
v7.0.0 -
Show latest stable
-
0 notes -
Class: Attribute
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0 (0)
- 6.1.3.1 (4)
- 6.1.7.7 (0)
- 7.0.0 (38)
- 7.1.3.2 (29)
- 7.1.3.4 (0)
- What's this?
has_rich_text(name, encrypted: false)
public
Provides access to a dependent RichText model that holds the body and attachments for a single named rich text attribute. This dependent attribute is lazily instantiated and will be auto-saved when it’s been changed. Example:
class Message < ActiveRecord::Base has_rich_text :content end message = Message.create!(content: "<h1>Funny times!</h1>") message.content? #=> true message.content.to_s # => "<h1>Funny times!</h1>" message.content.to_plain_text # => "Funny times!"
The dependent RichText model will also automatically process attachments links as sent via the Trix-powered editor. These attachments are associated with the RichText model using Active Storage.
If you wish to preload the dependent RichText model, you can use the named scope:
Message.all.with_rich_text_content # Avoids N+1 queries when you just want the body, not the attachments. Message.all.with_rich_text_content_and_embeds # Avoids N+1 queries when you just want the body and attachments. Message.all.with_all_rich_text # Loads all rich text associations. === Options * <tt>:encrypted</tt> - Pass true to encrypt the rich text attribute. The encryption will be non-deterministic. See +ActiveRecord::Encryption::EncryptableRecord.encrypts+. Default: false.