Rails 6.0.2.2 form_with using a nested partial renders the form contents outside of the <form></form> elements

I am seeing some strange behavior on Rails 6.0.2.2

My haml code is like this, but I also get this result using Erb syntax.

// skins/_list.haml

Edit
= skin.name

for
= skin.account.company_name

= form_with model: skin, url: edit_dashboard_skin_path(skin) do |f|
  = render partial: "form",  locals: {skin: skin, f: f}

Notice that the partial is rendered within the form, thus you would expect

<form action="/dashboard/skins/2/edit" accept-charset="UTF-8" data-remote="true" method="post">
   <input type="hidden" name="_method" value="patch">
   <input type="hidden" name="authenticity_token" value="67DBVfnagSrI+DZMxfv/calLBjWq8EV2YFqMDI8oJN/ltqp1jLh3Oa64gZBRhmY25nQUsZEuFK8P/UgCLII8AA==">
   /* other form fields here */
</form>

However, Rails seems to be rendering ALL of the form content—including the hidden fields and any arbitrary text I stick inside of the form_with do block, as siblings of the form, not children of the form .

PLEASE SEE SO POST FOR FOLLOW-UP HERE:

i think this might be a bug in Rails 6.0.2.2 so I am submitting it on the Rails issue tracker here Edit (but not create) Forms rendered through javascript using ERB appear to have their contents come after the close </form> tag, not within the form as expected · Issue #38919 · rails/rails · GitHub

stack overflow post here ruby on rails - form_with using a nested partial renders the form contents outside of the <form></form> elements tables, rendering content into a table row - Stack Overflow

any help would be appreciated!

I think that is not a rails issue, it turns to be on HTML.

It’s not allowed to place a form as a child element of a table, tbody, or tr. You can have an entire table inside a form. You can have a form inside a table cell. You cannot have part of a table inside a form.

Wrapping the table inside the form may solve the problem to you.

1 Like