Rails 3.1 Having iframe in view makes layout stop rendering

喜夏-厌秋 提交于 2019-12-21 19:24:10

问题


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.


回答1:


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.




回答2:


You have wrong on clossing ruby code place

<%= yield =>

The correct is

<%= yield %>


来源:https://stackoverflow.com/questions/7375325/rails-3-1-having-iframe-in-view-makes-layout-stop-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!