method
attachable_sgid
rails latest stable - Class:
ActionText::Attachable
attachable_sgid()public
Returns the Signed Global ID for the attachable. The purpose of the ID is set to ‘attachable’ so it can’t be reused for other purposes.
# File actiontext/lib/action_text/attachable.rb, line 77
def attachable_sgid
to_sgid(expires_in: nil, for: LOCATOR_NAME).to_s
end
def attachable_content_type
try(:content_type) || "application/octet-stream"
end
def attachable_filename
filename.to_s if respond_to?(:filename)
end
def attachable_filesize
try(:byte_size) || try(:filesize)
end
def attachable_metadata
try(:metadata) || {}
end
def previewable_attachable?
false
end
# Returns the path to the partial that is used for rendering the attachable
# in Trix. Defaults to +to_partial_path+.
#
# Override to render a different partial:
#
# class User < ApplicationRecord
# def to_trix_content_attachment_partial_path
# "users/trix_content_attachment"
# end
# end
def to_trix_content_attachment_partial_path
to_partial_path
end
# Returns the path to the partial that is used for rendering the attachable.
# Defaults to +to_partial_path+.
#
# Override to render a different partial:
#
# class User < ApplicationRecord
# def to_attachable_partial_path
# "users/attachable"
# end
# end
def to_attachable_partial_path
to_partial_path
end
def to_rich_text_attributes(attributes = {})
attributes.dup.tap do |attrs|
attrs[:sgid] = attachable_sgid
attrs[:content_type] = attachable_content_type
attrs[:previewable] = true if previewable_attachable?
attrs[:filename] = attachable_filename
attrs[:filesize] = attachable_filesize
attrs[:width] = attachable_metadata[:width]
attrs[:height] = attachable_metadata[:height]
end.compact
end
private
def attribute_names_for_serialization
super + ["attachable_sgid"]
end
def read_attribute_for_serialization(key)
if key == "attachable_sgid"
persisted? ? super : nil
else
super
end
end
end Related methods
- Class methods
- attachable_content_type
- attachable_filename
- attachable_filesize
- attachable_from_sgid
- attachable_metadata
- attachable_sgid
- attribute_names_for_serialization
- from_attachable_sgid
- from_node
- previewable_attachable?
- read_attribute_for_serialization
- to_attachable_partial_path
- to_missing_attachable_partial_path
- to_rich_text_attributes
- to_trix_content_attachment_partial_path