# Closing HTML Tags, or Containing HTML

**URL:** <https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583>\
**Category:** Rails\
**Created:** [August 22, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583 "2008-08-22T16:58:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [August 22, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/1 "2008-08-22T16:58:56Z")

</div>

How are you gentlemen?

I have a view where I need to render some HTML stored in site.html\_code

\<%= site.html\_code %\>

The problem is, when I do that, it changes all the links on the rest of  
the page that are pulled in by layout.

So instead of my “Home” link pointing to “/main/index”, it’ll now point  
to “URL\_FROM\_site.html\_code/[http://localhost:3000/main/index](http://localhost:3000/main/index)”.

I figure I can go in and change the navigation links in the layout, but  
is there a way to just “contain” the HTML from site.html\_code so that it  
doesn’t affect the rest of the page.

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [August 22, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/2 "2008-08-22T17:57:11Z")

</div>

Joe P. wrote:

> is there a way to just “contain” the HTML from site.html\_code so that it  
> doesn’t affect the rest of the page.

How are you displaying the views in your layout? Regardless of what you  
are rendering in the layout, the links shouldn’t be changing. I have  
views with links in them that don’t randomly change. Sounds like you  
might have some kind of HTML formatting issue. In my views I render the  
content by:

\<%=@content\_for\_layout%\>

Are you doing something similar? If html\_code is a partial you want to  
say:

\<%= render :partial =\> ‘html\_code’ %\>

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [August 25, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/3 "2008-08-25T15:43:52Z")

</div>

> How are you displaying the views in your layout? Regardless of what you  
> are rendering in the layout, the links shouldn’t be changing. I have  
> views with links in them that don’t randomly change. Sounds like you  
> might have some kind of HTML formatting issue. In my views I render the  
> content by:
> 
> \<%=@content\_for\_layout%\>
> 
> Are you doing something similar? If html\_code is a partial you want to  
> say:
> 
> \<%= render :partial =\> ‘html\_code’ %\>

I’m rendering the content in the layout like this:  
\<%= yield -%\>

When I render site.html\_code, html\_code is a column in the Sites table  
that holds the HTML of that Site. Is there any way to “encapsulate” the  
rendered HTML code so that it can’t affect the rest of the page?

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 5, 2008, 5:59pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/4 "2008-09-05T17:59:44Z")

</div>

> I’m rendering the content in the layout like this:  
> \<%= yield -%\>
> 
> When I render site.html\_code, html\_code is a column in the Sites table  
> that holds the HTML of that Site. Is there any way to “encapsulate” the  
> rendered HTML code so that it can’t affect the rest of the page?

I render “html\_code” like this:  
\<%= @site.html\_code %\>

Somehow, it is changing the nav-links in my layout. Might it have  
something to do that the “html\_code” is all the HTML from a Wayback  
result for the site?

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 5, 2008, 8:22pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/5 "2008-09-05T20:22:02Z")

</div>

Frederick C. wrote:

> It could conceivably make the browser do all sorts of things if what  
> you end up with is invalid html (unclosed tags etc…) or html  
> designed for a different doctype than your page. If it’s just all the  
> html from wayback (including for example the head or body tags) then  
> it’s going to be very yucky. sticking it in a frame/iframe might be  
> workable.
> 
> Fred

Thanks, it looks like iframes are the solution for me.

Only thing is, I’m having trouble getting it to just put @site.html\_code  
inside the iframe. Somehow, it keeps thinking that @site is a nil  
object.

Hmm, time to try to find out how to do this. If anyone has any ideas, I  
am all ears.

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 5, 2008, 9:31pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/6 "2008-09-05T21:31:28Z")

</div>

Okay, I figured it out. “src” has to be a URL, so I just did this.

Then in the controller:  
def show\_site\_html\_code  
@site = Site.find\_by\_id(params[:site\_id])  
render(:layout =\> false)  
end

Hopefully this can help someone else who wants to know how to use  
iframes with rails like this.

Good thread to read right here:  
[http://www.ruby-forum.com/topic/144196#new](http://www.ruby-forum.com/topic/144196#new)

---

<div class="post-metadata">

**Author:** ![joep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/87869e/32.png) [@joep](https://www.ruby-forum.com/u/joep)\
**Post date:** [September 5, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/closing-html-tags-or-containing-html/146583/7 "2008-09-05T18:04:03Z")

</div>

On 5 Sep 2008, at 16:59, Joe P. wrote:

> I render “html\_code” like this:  
> \<%= @site.html\_code %\>
> 
> Somehow, it is changing the nav-links in my layout. Might it have  
> something to do that the “html\_code” is all the HTML from a Wayback  
> result for the site?

It could conceivably make the browser do all sorts of things if what  
you end up with is invalid html (unclosed tags etc…) or html  
designed for a different doctype than your page. If it’s just all the  
html from wayback (including for example the head or body tags) then  
it’s going to be very yucky. sticking it in a frame/iframe might be  
workable.

Fred
