Ruby on Rails Sunday, September 29, 2013

On Sep 29, 2013, at 4:10 AM, Colin Law wrote:

>> the app/views/sessions/new.html.rb code
>> 9 <div class="offset4 span4 border-radius">
>> 20 <form id="sign-in">
>> 21 <legend>Sign In with your email address and password</legend>
>> 22 <%= form_for(:session, url: sessions_path) do |f| %>
> It is not legal html to have nested forms.
> Colin

And the point of that is that the browser will take apart that illegal page and make a valid form out of it, ignoring the nested child. Make this into a test page in your text editor, and view it in a browser.

<!DOCTYPE html>
<meta charset="utf-8" />
<form action="foo" method="get" accept-charset="utf-8">
<form action="bar" method="get" accept-charset="utf-8">
<p><input type="text" value="baz"/></p>
<p><input type="text" value="boo"/></p>

If you view source, and actually look at the source code, you'll see what I typed here. If you view the DOM (what the browser made out of it) you will see this instead:

<!DOCTYPE html>
<meta charset="utf-8">
<form action="foo" method="get" accept-charset="utf-8">

<p><input type="text" value="baz"></p>
<p><input type="text" value="boo"></p>

See how the outer form is all that is left, and the inner form's contents have been shifted outside of the outer form entirely? That's just what Safari does -- other browsers may put the elements in a slightly different order -- but you can't control this. The only way around it is to code a valid HTML page. Then, if the browsers mess it up, that's on them, not you.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment