trix: form field doesn't clear on submit when containing an image
If I put an image in the form field when I submit the form the create action in the controller completes with a successful commit and everything’s in the database ok but the field doesn’t clear
<%= form_with model: @message, multipart: true, remote: true do |f| %> <%= f.rich_text_area :content, class: ‘form-control’ %> <%= f.hidden_field :recipients, value: @conversation_with.id %> <%= f.hidden_field :sender, value: current_user.id %> <%= f.submit ‘Send’ %> <% end %>
def create @message = Message.new(message_params) respond_to do |format| if @message.save format.js ActionCable.server.broadcast ‘room_channel’, content: @message.content, msg_time: Time.now, recipients: @message.recipients, sender: @message.sender, sender_name: User.find(@message.sender).name end end end
Details
(3.6ms) COMMIT
↳ app/controllers/messages_controller.rb:29:in create' User Load (2.1ms) SELECT users.* FROM usersWHEREusers.id= 1 LIMIT 1 ↳ app/controllers/messages_controller.rb:30:increate’
ActiveStorage::Blob Load (0.8ms) SELECT active_storage_blobs.* FROM active_storage_blobs WHERE active_storage_blobs.id = 15 LIMIT 1
↳ app/controllers/messages_controller.rb:30:in `create’
Rendered active_storage/blobs/_blob.html.erb (Duration: 2.6ms | Allocations: 521)
Rendered /home/fugee/.rvm/gems/ruby-2.6.5/gems/actiontext-6.0.0/app/views/action_text/content/_layout.html.erb (Duration: 18.0ms | Allocations: 3713)
[ActionCable] Broadcasting to room_channel: {:content=>#<ActionText::RichText id: 92, name: “content”, body: #<ActionText::Content “<div class="trix-conte…”>, record_type: “Message”, record_id: 332, created_at: “2020-01-23 09:07:16”, updated_at: “2020-01-23 09:07:16”>, :msg_time=>2020-01-23 04:07:16 -0500, :recipients=>3, :sender=>1, :sender_name=>“fugee”}
RoomChannel transmitting {“content”=>{“id”=>92, “name”=>“content”, “body”=>"<div><action-text-attachment sgid="BAh7CEkiCGdpZAY6BkVUSSI4Z2lkOi8vaWduYXR6bW91c2UvQWN0aXZlU3RvcmFnZTo6QmxvYi8xNT9leHBpcmVzX2luBjsAVEkiDHB1cnBvc2UGOwBUSSIPYXR0YWNoYWJsZQY7AFRJIg9leHBpcmVzX2F0BjsAVDA=–2ef70fd7ee7158e49597945edacc6988d695af54" c… (via streamed from room_channel)
No template found for MessagesController#create, rendering head :no_content
Completed 204 No Content in 139ms (ActiveRecord: 16.5ms | Allocations: 30044)
- Trix version:
- Browser name and version:
- Operating system:
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 26 (13 by maintainers)
Not a trix issue
Hey @mices, thanks for creating this issue.
Your form is POSTing to your /messages route, and your controller is only rendering head, since no template has been found.
If you want the form field to be cleared, you should probably redirect to the current page, to render the same template:
You could also clear your trix editor dynamically by loading an empty state:
I don’t think the
trix-editorcustom element is aware if it’s part of a form or not, so in that sense, I believe you are in charge of clearing it.I hope this helps! Let me know if you have any other question. Cheers!