Sorry, I wasn’t clear enough. I meant the request was made from out of a turbo frame:
<%= turbo_frame_tag "new_discussion_message", src: new_discussion_message_path(@discussion), target: "_top" %>
<%= turbo_frame_tag "new_discussion_message", target: "_top" do %>
<%= form_with model: [@discussion, @message], class: 'new-discussion__form push-double--top d-flex flex-column' do |f| %>
<%= f.hidden_field :creator_id %>
<%= f.rich_text_area :content, data: { controller: "signatured-input", signatured_input_signature: Current.user.signature.to_s } %>
<footer class="new-discussion__footer">
<p class="push--bottom" style="font-size: 1.8rem;">
<%= image_tag @discussion.parent.client.avatar_url %>
<%= @discussion.parent.client.name %> will receive your message in their email.
</p>
<%= f.button class: 'btn btn-primary btn--with-icon', type: 'submit', data: { "disable_with": "Sending…" } do %>
Reply
<% end %>
</footer>
<% end %>
<% end %>
def create
@message = @discussion.messages.new(message_params)
respond_to do |format|
if @message.save
format.any(:html, :js) { redirect_to @discussion.parent.client, flash: { follow_up_with_new_task: true } }
end
end
end
This, however, doesn’t cover the case where @message.save
fails the validations. Though you could send a turbo_stream
on validation failure to render the errors in your frame.