Rails 3.1 在视图中包含 iframe 会使布局停止渲染
所以我有一个基本的布局文件:
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<%= stylesheet_link_tag "logged_out" %>
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" %>
</head>
<body>
<!-- header stuff here -->
<%= yield %>
<!-- footer stuff here -->
</body>
</html>
并且对于任何普通的 html 都可以。但是,如果我将这样的 iframe 添加到视图中:
<iframe id="form" height="480" width="320" src="/mobile_preview/preview"/>
当我渲染页面时,所有内容都会渲染到 iframe 之前,但产量之后的页脚内容不会渲染。以前有人遇到过这个吗?
编辑:正如其中一个答案所指出的(谢谢!),我最初问题中的产量声明是错误的。我的代码中的yield语句是正确的,但这是转移到stackoverflow时的一个拼写错误。
注意:如果您尝试使用 jquery mobile 复制 iframe。
So I have a basic layout file:
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<%= stylesheet_link_tag "logged_out" %>
<%= javascript_include_tag "application" %>
<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" %>
</head>
<body>
<!-- header stuff here -->
<%= yield %>
<!-- footer stuff here -->
</body>
</html>
And with any normal html its fine. However if I add in an iframe like this to a view:
<iframe id="form" height="480" width="320" src="/mobile_preview/preview"/>
When I render the page everything is rendered up until the iframe, but the footer stuff after yield doesn't render. Has anyone run into this before?
EDIT: As one of the answers pointed out (thank you!), my yield statement in my initial question was wrong. My yield statement in my code is correct though, it was a typo when transferring to stackoverflow.
NOTE: If you are trying to replicate the iframe is using jquery mobile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题在于如何包含
。您认为您包含了自关闭标签,它就到此结束了。但是您不会将页面作为 XML 发送,并且 HTML 没有自闭合标签的概念,它只是最后的垃圾。因此,您的:
实际上被解释为:
并且页面的其余部分被解释为
标记内的忽略内容。这就是为什么您不应该在 HTML 文档中使用自关闭标签的原因 - 它们实际上并不像您想象的那样工作。
将其更改为:
如果您使用 Firebug 或 Chrome Inspector 查看解析的 DOM 树,您可以找到它。
额外的好处是:它与 Rails 无关,服务器像以前一样返回响应,您可以在日志中看到它。这只是浏览器如何解释您的标记的问题。
The problem is how you include
<iframe>
. You think you included self-closing tag, and it ends there. But you don't send your page as XML, and HTML doesn't have concept of self-closing tags, it's just garbage at the end. So your:is really interpreted as:
and rest of the page is interpreted as ignored content inside
<iframe>
tag. That's why you shouldn't use self-closing tags in HTML document - they don't really work the way you think they work.Change it to:
You could found it if you looked at parsed DOM tree with Firebug or Chrome Inspector.
As a bonus: it has nothing to do with Rails, server returns response just as previously, you could see it in logs. It's just a matter how your markup is interpreted by browsers.
你关闭 ruby 代码的位置是错误的,
正确的是
You have wrong on clossing ruby code place
The correct is