Skip to content

Commit 71a89d5

Browse files
committed
Document more methods for ActionText::Attachable [ci-skip]
Document the `*_partial_path`, `attachable_sgid` and `as_json` methods.
1 parent 68b500e commit 71a89d5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

actiontext/lib/action_text/attachable.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,23 @@ def from_attachable_sgid(sgid)
5757
ActionText::Attachable.from_attachable_sgid(sgid, only: self)
5858
end
5959

60+
# Returns the path to the partial that is used for rendering missing attachables.
61+
# Defaults to "action_text/attachables/missing_attachable".
62+
#
63+
# Override to render a different partial:
64+
#
65+
# class User < ApplicationRecord
66+
# def self.to_missing_attachable_partial_path
67+
# "users/missing_attachable"
68+
# end
69+
# end
6070
def to_missing_attachable_partial_path
6171
ActionText::Attachables::MissingAttachable::DEFAULT_PARTIAL_PATH
6272
end
6373
end
6474

75+
# Returns the Signed Global ID for the attachable. The purpose of the ID is
76+
# set to 'attachable' so it can't be reused for other purposes.
6577
def attachable_sgid
6678
to_sgid(expires_in: nil, for: LOCATOR_NAME).to_s
6779
end
@@ -86,14 +98,35 @@ def previewable_attachable?
8698
false
8799
end
88100

101+
# Returns the attachable as JSON with the +attachable_sgid+ included.
89102
def as_json(*)
90103
super.merge("attachable_sgid" => persisted? ? attachable_sgid : nil)
91104
end
92105

106+
# Returns the path to the partial that is used for rendering the attachable
107+
# in Trix. Defaults to +to_partial_path+.
108+
#
109+
# Override to render a different partial:
110+
#
111+
# class User < ApplicationRecord
112+
# def to_trix_content_attachment_partial_path
113+
# "users/trix_content_attachment"
114+
# end
115+
# end
93116
def to_trix_content_attachment_partial_path
94117
to_partial_path
95118
end
96119

120+
# Returns the path to the partial that is used for rendering the attachable.
121+
# Defaults to +to_partial_path+.
122+
#
123+
# Override to render a different partial:
124+
#
125+
# class User < ApplicationRecord
126+
# def to_attachable_partial_path
127+
# "users/attachable"
128+
# end
129+
# end
97130
def to_attachable_partial_path
98131
to_partial_path
99132
end

0 commit comments

Comments
 (0)