1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Always render attachment partials as HTML with :html format inside trix editor

This commit is contained in:
James Brooks 2021-03-20 04:05:09 +10:30 committed by GitHub
parent 1598ad5c4b
commit b1b0b22f50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -28,7 +28,7 @@ module ActionText
private
def trix_attachment_content
if partial_path = attachable.try(:to_trix_content_attachment_partial_path)
ActionText::Content.render(partial: partial_path, object: self, as: model_name.element)
ActionText::Content.render(partial: partial_path, formats: :html, object: self, as: model_name.element)
end
end
end

View file

@ -0,0 +1,4 @@
{
"id": <%= @message.id %>,
"form": "<%= j render partial: "form", formats: :html, locals: { message: @message } %>"
}

View file

@ -24,6 +24,15 @@ class ActionText::ControllerRenderTest < ActionDispatch::IntegrationTest
assert_select content, "img:match('src', ?)", %r"//loocalhoost/.+/racecar"
end
test "renders Trix with content attachment as HTML when the request format is not HTML" do
message_with_person_attachment = messages(:hello_alice)
get edit_message_path(message_with_person_attachment, format: :json)
form_html = response.parsed_body["form"]
assert_match %r" class=\S+mentionable-person\b", form_html
end
test "resolves partials when controller is namespaced" do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg")
message = Message.create!(content: ActionText::Content.new.append_attachables(blob))