# Template html/xhtml confusion in Rails 2

**URL:** <https://www.ruby-forum.com/t/template-html-xhtml-confusion-in-rails-2/137519>\
**Category:** Rails\
**Created:** [May 13, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/template-html-xhtml-confusion-in-rails-2/137519 "2008-05-13T22:52:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@sebastian](https://www.ruby-forum.com/u/sebastian)\
**Post date:** [May 13, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/template-html-xhtml-confusion-in-rails-2/137519/1 "2008-05-13T22:52:14Z")

</div>

Doing my first Rails 2 project I’m utterly confused by Rails’ behavior  
concerning the use of html or xhtml in templates and the MIME types  
the final documents get send as.  
I have one controller that uses a layout. Within the layout tag helper  
methods return xhtml self-closing tag. But in the template for the  
individual actions html tags are used. The final document is  
transmitted as application/xml.  
Another controller — without a layout — transmits its actions as text/  
html but uses xhtml tags.  
I have not tempered with any configs regarding this. I only  
experimented with the new template extensions, but found that  
using .xhtml.erb was not the way to toggle between the use of html or  
xhtml.  
Can anybody please shed some light on this, please?  
Thank you!

---

<div class="post-metadata">

**Author:** ![sebastian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@sebastian](https://www.ruby-forum.com/u/sebastian)\
**Post date:** [May 13, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/template-html-xhtml-confusion-in-rails-2/137519/2 "2008-05-13T23:15:43Z")

</div>

sebastian wrote:

> Doing my first Rails 2 project I’m utterly confused by Rails’ behavior  
> concerning the use of html or xhtml in templates and the MIME types  
> the final documents get send as.  
> I have one controller that uses a layout. Within the layout tag helper  
> methods return xhtml self-closing tag. But in the template for the  
> individual actions html tags are used. The final document is  
> transmitted as application/xml.  
> Another controller ï¿½ without a layout ï¿½ transmits its actions as text/  
> html but uses xhtml tags.  
> I have not tempered with any configs regarding this. I only  
> experimented with the new template extensions, but found that  
> using .xhtml.erb was not the way to toggle between the use of html or  
> xhtml.  
> Can anybody please shed some light on this, please?  
> Thank you!

Im not sure whats going on in your headers, but I am confused that you  
say you are getting mixed html and xhtml tags in your code. All the  
rails tag helpers should generate xhtml just fine. Other than that,  
rails won’t process your HTML at all. So if you insert unclosed single  
tags in your erb templates, thats exactly how they will be sent out.

---

<div class="post-metadata">

**Author:** ![sebastian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@sebastian](https://www.ruby-forum.com/u/sebastian)\
**Post date:** [May 14, 2008, 11:02am UTC](https://www.ruby-forum.com/t/template-html-xhtml-confusion-in-rails-2/137519/3 "2008-05-14T11:02:43Z")

</div>

Thanks for the reply, Alex  
You are, of course, right: the stray html tags where after all my own  
doing.  
And that one controller returned application/xml stemmed from the  
circumstance that in its layout I use a Builder template.  
Sometimes it’s just better to call it a day early and sleep it over â€”  
in this case at 4 pm. 🙂  
Cheers,  
Sebastian

On May 13, 10:15Â pm, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
