instance method
to_plain_text
Ruby on Rails 8.0.4
Since v6.0.6Signature
to_plain_text()
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]"
Source
# File actiontext/lib/action_text/attachment.rb, line 110
def to_plain_text
if respond_to?(:attachable_plain_text_representation)
attachable_plain_text_representation(caption)
else
caption.to_s
end
end
Defined in actiontext/lib/action_text/attachment.rb line 110
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionText::Attachment