method
to_plain_text
rails latest stable - Class:
ActionText::Attachment
to_plain_text()public
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]"