mirror of https://github.com/rails/rails
Always render attachment partials as HTML with :html format inside trix editor
This commit is contained in:
parent
1598ad5c4b
commit
b1b0b22f50
|
@ -28,7 +28,7 @@ module ActionText
|
||||||
private
|
private
|
||||||
def trix_attachment_content
|
def trix_attachment_content
|
||||||
if partial_path = attachable.try(:to_trix_content_attachment_partial_path)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"id": <%= @message.id %>,
|
||||||
|
"form": "<%= j render partial: "form", formats: :html, locals: { message: @message } %>"
|
||||||
|
}
|
|
@ -24,6 +24,15 @@ class ActionText::ControllerRenderTest < ActionDispatch::IntegrationTest
|
||||||
assert_select content, "img:match('src', ?)", %r"//loocalhoost/.+/racecar"
|
assert_select content, "img:match('src', ?)", %r"//loocalhoost/.+/racecar"
|
||||||
end
|
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
|
test "resolves partials when controller is namespaced" do
|
||||||
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg")
|
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpg")
|
||||||
message = Message.create!(content: ActionText::Content.new.append_attachables(blob))
|
message = Message.create!(content: ActionText::Content.new.append_attachables(blob))
|
||||||
|
|
Loading…
Reference in New Issue