Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>

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.

like image 384
Msencenb Avatar asked Dec 03 '22 07:12

Msencenb


2 Answers

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.

like image 186
MBO Avatar answered Feb 24 '23 08:02

MBO


You have wrong on clossing ruby code place

<%= yield =>

The correct is

<%= yield %>
like image 42
mike zaby Avatar answered Feb 24 '23 07:02

mike zaby