Rails 3.1在视图中使用iframe使布局停止渲染 [英] Rails 3.1 Having iframe in view makes layout stop rendering
问题描述
所以我有一个基本的布局文件:
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>
任何普通的html都可以。但是,如果我将这样的iframe添加到视图中:
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"/>
当我渲染页面时,所有内容都会渲染到iframe,但是在yield之后的页脚内容没有t渲染。有没有人遇到过这个?
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?
编辑:正如其中一个答案所指出的(谢谢!),我在最初的问题中的收益率陈述是错误的。我的代码中的yield语句是正确的,但是当转移到stackoverflow时它是一个错字。
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.
注意:如果你试图复制iframe使用的是jquery mobile。
NOTE: If you are trying to replicate the iframe is using jquery mobile.
推荐答案
问题在于如何包含< iframe>
。你认为你包括自我关闭标签,并在那里结束。但是你没有把你的页面作为XML发送,并且HTML没有自闭标签的概念,最后它只是垃圾。所以你的:
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:
<iframe id="form" height="480" width="320" src="/mobile_preview/preview"/>
实际上解释为:
<iframe id="form" height="480" width="320" src="/mobile_preview/preview">
该页面的其余部分被解释为< iframe>内的忽略内容
标签。这就是为什么你不应该在HTML文档中使用自闭标签 - 它们并不像你认为的那样工作。
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.
将其更改为:
<iframe id="form" height="480" width="320" src="/mobile_preview/preview"></iframe>
如果你用Firebug或Chrome Inspector查看已解析的DOM树,你可以找到它。
You could found it if you looked at parsed DOM tree with Firebug or Chrome Inspector.
作为奖励:它与Rails无关,服务器返回响应就像以前一样,你可以在日志中看到它。这只是浏览器如何解释标记的问题。
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.
这篇关于Rails 3.1在视图中使用iframe使布局停止渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!