Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form_tag doesn't compile as expected while using render :layout with erb partial #118

Open
zernel opened this issue Oct 9, 2016 · 4 comments

Comments

@zernel
Copy link

zernel commented Oct 9, 2016

Hi there, I have got a problem when I try to render a erb partial as layout, actually there are 2 key elements to reproduce:

  1. render erb partial as layout in haml template
  2. form_tag in erb partial

Please check the sample code below:

# template.haml
= render layout: 'form' do
  %h4
    Test

# form.html.erb
<%= yield %>
<%= form_tag '/test' do -%>
  <%= text_field_tag :test %>
  <%= submit_tag %>
<%end -%>

this gets compiled to:

<h4>Test</h4>

<input type="text" name="test" id="test">
<input type="submit" name="commit" value="Save changes">
<form action="/test" accept-charset="UTF-8" method="post">
   <input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="...">
</form>

The form content were render in wrong place (outside of form tag), it will work correctly if I rewrite the form.html.erb to haml, I guess that maybe a bug.

@serv
Copy link
Contributor

serv commented Oct 9, 2016

I am noticing a few things that are raising red flags.

  • <%= yield %> is outside the form_tag. Maybe input tags are being inserted with yield.
  • Change <%end -%> to just <% end %>

@zernel
Copy link
Author

zernel commented Oct 10, 2016

@serv good point, I try to move the yield into form_tag and even remove the yield from partial, neither is working (the input tags are still outside). And I try to change the <% end %> but still no lucky.
It will work if I write form tag manually instead using form_tag helper method. Something is wrong while rendering the form_tag in this case.

Anyway, thanks for your time :)

@zernel
Copy link
Author

zernel commented Oct 10, 2016

After digging more in the source code, I found the block became empty while it's execute in form_tag, but still not find the reason. quite weird.

@syguer
Copy link
Member

syguer commented May 19, 2017

@zernel please let me know version of rails and haml. Is it still happen on latest both version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants