Flowdock
method

to_plain_text

Importance_2
v7.1.3.2 - Show latest stable - 0 notes - Class: 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]"
Show source
Register or log in to add new notes.