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>
<html>
<head>
<meta charset="utf-8" />
<title>untitled</title>
</head>
<body>
<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>
</form>
<p><input type="text" value="boo"/></p>
</form>
</body>
</html>

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>
<html><head>
<meta charset="utf-8">
<title>untitled</title>
</head>
<body>
<form action="foo" method="get" accept-charset="utf-8">

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

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.

Walter

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4A7D621E-FA89-4349-AFDB-0F800AC47A1F%40wdstudio.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment