Action Text Attachment
¶ ↑
Attachments
serialize attachables to HTML or plain text.
class Person < ApplicationRecord include ActionText::Attachable end attachable = Person.create! name: "Javan" attachment = ActionText::Attachment.from_attachable(attachable) attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk..."
Methods
- C
- F
- I
- N
- T
- W
Constants
ATTRIBUTES | = | %w( sgid content-type url href filename filesize width height previewable presentation caption content ) |
Attributes
[R] | attachable | |
[R] | node |
Class Public methods
fragment_by_canonicalizing_attachments(content) Link
from_attachable(attachable, attributes = {}) Link
from_attachables(attachables) Link
from_attributes(attributes, attachable = nil) Link
from_node(node, attachable = nil) Link
new(node, attachable) Link
Instance Public methods
caption() Link
full_attributes() Link
inspect() Link
to_html() Link
Converts the attachment to HTML.
attachable = Person.create! name: "Javan" attachment = ActionText::Attachment.from_attachable(attachable) attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk...
to_plain_text() Link
Converts the attachment to plain text.
attachable = ActiveStorage::Blob.find_by filename: "racecar.jpg" attachment = ActionText::Attachment.from_attachable(attachable) attachment.to_plain_text # => "[racecar.jpg]"
Use the caption
when set:
attachment = ActionText::Attachment.from_attachable(attachable, caption: "Vroom vroom") attachment.to_plain_text # => "[Vroom vroom]"
The presentation can be overridden by implementing the attachable_plain_text_representation
method:
class Person < ApplicationRecord include ActionText::Attachable def attachable_plain_text_representation "[#{name}]" end end attachable = Person.create! name: "Javan" attachment = ActionText::Attachment.from_attachable(attachable) attachment.to_plain_text # => "[Javan]"