Rails 3.1 在视图中包含 iframe 会使布局停止渲染

发布于 2024-12-03 20:12:57 字数 850 浏览 1 评论 0原文

所以我有一个基本的布局文件:

<!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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-12-10 20:12:57

问题在于如何包含 。您认为您包含了自关闭标签,它就到此结束了。但是您不会将页面作为 XML 发送,并且 HTML 没有自闭合标签的概念,它只是最后的垃圾。因此,您的:

<iframe id="form" height="480" width="320" src="/mobile_preview/preview"/>

实际上被解释为:

<iframe id="form" height="480" width="320" src="/mobile_preview/preview">

并且页面的其余部分被解释为 标记内的忽略内容。这就是为什么您不应该在 HTML 文档中使用自关闭标签的原因 - 它们实际上并不像您想象的那样工作。

将其更改为:

<iframe id="form" height="480" width="320" src="/mobile_preview/preview"></iframe>

如果您使用 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:

<iframe id="form" height="480" width="320" src="/mobile_preview/preview"/>

is really interpreted as:

<iframe id="form" height="480" width="320" src="/mobile_preview/preview">

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:

<iframe id="form" height="480" width="320" src="/mobile_preview/preview"></iframe>

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.

蓝海 2024-12-10 20:12:57

你关闭 ruby​​ 代码的位置是错误的,

<%= yield =>

正确的是

<%= yield %>

You have wrong on clossing ruby code place

<%= yield =>

The correct is

<%= yield %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文