Action Text Attachment¶ ↑
Attachments 将附件序列化为 HTML 或纯文本。
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..."
方法
- C
- F
- I
- N
- T
- W
常量
| ATTRIBUTES | = | %w( sgid content-type url href filename filesize width height previewable presentation caption content ) |
Attributes
| [R] | attachable | |
| [R] | node |
类公共方法
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
实例公共方法
caption() Link
full_attributes() Link
inspect() Link
to_html() Link
将附件转换为 HTML。
attachable = Person.create! name: "Javan" attachment = ActionText::Attachment.from_attachable(attachable) attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk...
to_plain_text() Link
将附件转换为纯文本。
attachable = ActiveStorage::Blob.find_by filename: "racecar.jpg" attachment = ActionText::Attachment.from_attachable(attachable) attachment.to_plain_text # => "[racecar.jpg]"
如果设置了 caption,则使用它。
attachment = ActionText::Attachment.from_attachable(attachable, caption: "Vroom vroom") attachment.to_plain_text # => "[Vroom vroom]"
可以通过实现 attachable_plain_text_representation 方法来覆盖呈现方式。
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]"