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:
parent
1598ad5c4b
commit
b1b0b22f50
3 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
4
actiontext/test/dummy/app/views/messages/edit.json.erb
Normal file
4
actiontext/test/dummy/app/views/messages/edit.json.erb
Normal file
|
@ -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"
|
||||
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))
|
||||
|
|
Loading…
Reference in a new issue