Ask A Question

Notifications

You’re not receiving notifications from this thread.

Hotwire missing template on form submission

Thomas McDonnell asked in Gems / Libraries

Hi Chris/extended go-rails community :)

I have been playing around with the new turbo rails and trying to implement a turbo stream for my login form submission errors. I am wondering if anyone else has come across this issue, my form submission takes place as it should and on turbo format response it looks as though it is working correctly and rendering the form template with errors, however, I am getting a 500 missing template error ActionView::MissingTemplate (Missing template <turbo-stream action="replace" target="new_user_session"><template><form id="new_user_session" class="grid grid-cols-6 gap-2" data-controller="accounts--form" action="/accounts/sessions" accept-charset="UTF-8" data-remote="true" method="post"><input type="hidden" name="authenticity_token" value="fJcDVQYgDyfW53OdG5D7wptzyLMu6qS/CGgBhoTunJKNb8Ri9QBAHxY3eCuYhi6f29wYaqwzP/j1A6W8FtzLMw==" />
<div class="col-span-6 field">
<div class="field_with_errors"><label class="block text-md font-medium text-gray-700" for="user_session_email">Email</label></div>
<div class="field_with_errors"><input class="mt-1 bg-gray-100 focus:outline-none focus:ring focus:border-purple-300 focus:bg-white border border-gray-200 block w-full sm:text-sm rounded-lg py-3 px-4 mb-3" required="required" type="email" value="test@t.com" name="user_session[email]" id="user_session_email" /></div>
</div> .....
which is confusing me as I can't think of what template it is looking for as the error correctly renders the form with errors so it's not the form partial.

Running Rails 6.0.3.4 and Ruby 2.7.0

Reply

Three days on this, digging into source code of turbo-rails and seeing how it works only to find it was a simple syntax error LOL The error messages could be better I think, but then again I could have just put my glasses on earlier to :)

Reply

Hi Thomas!
Can you share what you found? (Regarding the syntax error)
I am a bit stuck myself too.

Reply

Hey Francisco. Just ran into this myself, not sure if you are still looking into this, but my problem was with a render call I was making in the controller

Bad syntax:

render turbo_stream.replace(
dom_id_for_records(@commentable, @comment),
partial: 'comments/form',
locals: { comment: @comment, commentable: @commentable }
)

Good syntax:

render turbo_stream: turbo_stream.replace(
dom_id_for_records(@commentable, @comment),
partial: 'comments/form',
locals: { comment: @comment, commentable: @commentable }
)

...difference being the turbo_stream: after render

Reply

Hey Jake,
This is really helpful so thank you!

You are posting this as it should be laid out in the controller, but in my case, I am actually using a turbo stream page called index.turbo_stream.erb to render the contents from the server. I am experiencing the exact same issue described in the original post, but I can't figure out how to have turbo recognize this and render the content.

Here's what that index.turbo_stream.erb looks like:

<%= turbo_stream_action_tag(
  "append",
  target: "card-list",
  template: %(#{render partial: 'admin/card', collection: @results, as: :result })
) %>
<%= turbo_stream_action_tag(
  "replace",
  target: "pager",
  template: %(#{render "pager", pagy: @pagy})
) %>

In my controller I'm simply doing the following:

respond_to do |format|
    format.html
    format.turbo_stream
end

How do I modify the stream template to recognize the partial and render the content correctly?

Reply

Thank you thomas good luck

Reply

omg, God bless u man

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.