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 ) |
属性
[R] | attachable | |
[R] | node |
类公共方法
fragment_by_canonicalizing_attachments(content) 链接
from_attachable(attachable, attributes = {}) 链接
from_attachables(attachables) 链接
from_attributes(attributes, attachable = nil) 链接
from_node(node, attachable = nil) 链接
new(node, attachable) 链接
实例公共方法
full_attributes() 链接
inspect() 链接
to_html() 链接
将附件转换为 HTML。
attachable = Person.create! name: "Javan"
attachment = ActionText::Attachment.from_attachable(attachable)
attachment.to_html # => "<action-text-attachment sgid=\"BAh7CEk...
to_plain_text() 链接
将附件转换为纯文本。
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]"