I have my models setup like this, making page override the default partial path
class Post < ApplicationRecord
has_rich_text :body
end
class Page < ApplicationRecord
include ActionText::Attachable
def to_attachable_partial_path
"pages/page_embed"
end
On creating a new post, the attachment displays the correct partial pages/page_embed
And again on show pages/page_embed
But on edit, it shows pages#page
My _form code for that field is
<%= form.rich_text_area :body, rows: 4, data: { target: "attachments.editor" } %>
anyone any ideas?
class Page < ApplicationRecord
include ActionText::Attachable
def to_attachable_partial_path
"pages/page_embed"
end
# this
def to_trix_content_attachment_partial_path
to_attachable_partial_path
end
end
https://github.com/rails/rails/blob/v7.0.4.3/actiontext/lib/action_text/attachable.rb#L70
I think, maybe this was overlooked when to_attachable_partial_path
was introduced. The docs say:
Action Text renders embedded
<action-text-attachment>
elements by resolving theirsgid
attribute into an instance. Once resolved, that instance is passed along torender
. The resulting HTML is embedded as a descendant of the<action-text-attachment>
element.
To render a different partial, define User#to_attachable_partial_path:
Doesn't really say anything about editing. And if you remove the default users/_user.html.erb
the edit page breaks. I was thinking ActiveStorage images render no problem, what do they do: they ignore that method. I guess when they say render
it doesn't include rendering the edit field.