# Using RoR to produce .xhtml files

**URL:** <https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445>\
**Category:** Rails\
**Created:** [July 14, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445 "2006-07-14T20:31:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 14, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/1 "2006-07-14T20:31:09Z")

</div>

How can I manipulate RoR to produce an .xhtml file from the view  
template(s)? I see how I can use layouts and paritals to efficiently  
produce the content and tags that I need, but how can I get the actual  
file that’s produced to be named with the .xhtml suffix, (rather than  
\*.htm, as it currently is)? [Note: I never thought the suffix was all  
that important, but evidenly Mozilla won’t behave in some cases unless  
the files is named with the xhtml suffix.]

thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 14, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/2 "2006-07-14T20:53:57Z")

</div>

What??  
Make sure your output validates and contains the correct doctype. I’ve  
never  
heard of such a thing. If this is true, I’d love to know more about it.

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 14, 2006, 11:28pm UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/3 "2006-07-14T23:28:59Z")

</div>

Well, I made some changes, and now the output is validating when saved  
as an .xhtml file, and “tenatively validating” (“no character encoding  
found”) when the identical file is saved as .html.

Still, the .xhtml page renders perfectly in Mozilla, but the .html page  
does not. (I’m using MathML to display some equations, and these are  
the problems spots – MathML only seems to work if the file has an  
.xhtml suffix.)

Regardless, there must be some way to tailer RoR to a specific output  
file extension. No?

Thanks so much.

Brian H. wrote:

> What??  
> Make sure your output validates and contains the correct doctype. I’ve  
> never  
> heard of such a thing. If this is true, I’d love to know more about it.

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 14, 2006, 11:47pm UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/4 "2006-07-14T23:47:13Z")

</div>

On Fri, 14 Jul 2006, Alex A. wrote:

> Still, the .xhtml page renders perfectly in Mozilla, but the .html page  
> does not. (I’m using MathML to display some equations, and these are  
> the problems spots – MathML only seems to work if the file has an  
> .xhtml suffix.)

My experience was that if the .html was served with the correct doctype  
as  
application/xhtml+xml that MathML worked, but this was some time ago.

See: [XHTML Media Types - Second Edition](http://www.w3.org/TR/xhtml-media-types/)

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 16, 2006, 12:45am UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/5 "2006-07-16T00:45:25Z")

</div>

To answer your question, you can set URL rewriting (including  
adding .xhtml to the end) using routes.  
[http://manuals.rubyonrails.com/read/chapter/65](http://manuals.rubyonrails.com/read/chapter/65)

However, I agree with your other responders that you shouldn’t need  
to do this, and it’s better to keep the URLs clean and without  
extensions.  
[http://www.w3.org/Provider/Style/URI](http://www.w3.org/Provider/Style/URI)

```
        - dan

```

–  
Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 15, 2006, 3:31am UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/6 "2006-07-15T03:31:32Z")

</div>

Alex A. wrote:

> Well, I made some changes, and now the output is validating when saved  
> as an .xhtml file, and “tenatively validating” (“no character encoding  
> found”) when the identical file is saved as .html.

You set the encoding in the http headers, easy to do w/ a filter in the  
app controller. Here’s a ref:  
[http://wiki.rubyonrails.com/rails/pages/HowtoSetDefaultEncoding](http://wiki.rubyonrails.com/rails/pages/HowtoSetDefaultEncoding)

> Still, the .xhtml page renders perfectly in Mozilla, but the .html page  
> does not. (I’m using MathML to display some equations, and these are  
> the problems spots – MathML only seems to work if the file has an  
> .xhtml suffix.)
> 
> Regardless, there must be some way to tailer RoR to a specific output  
> file extension. No?

Try URL rewriting in your webserver, or hacking around in routes.rb.  
But you really shouldn’t need to do this. Have you set the doctype  
correctly in your layout/views?

There’s reference info on how to declare the processing instructions for  
docs with MathML, have you seen:  
[http://www.w3.org/Math/XSL/](http://www.w3.org/Math/XSL/)

cheers,  
phil

---

<div class="post-metadata">

**Author:** ![alexamat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bc8723/32.png) [@alexamat](https://www.ruby-forum.com/u/alexamat)\
**Post date:** [July 17, 2006, 2:04pm UTC](https://www.ruby-forum.com/t/using-ror-to-produce-xhtml-files/98445/7 "2006-07-17T14:04:07Z")

</div>

Everyone, thanks so much. This has been invaluably helpful. Thanks so  
much for your patience and assistance.

Dan K. wrote:

> To answer your question, you can set URL rewriting (including  
> adding .xhtml to the end) using routes.  
> [Peak Obsession](http://manuals.rubyonrails.com/read/chapter/65)
> 
> However, I agree with your other responders that you shouldn’t need  
> to do this, and it’s better to keep the URLs clean and without  
> extensions.  
> [Hypertext Style: Cool URIs don't change.](http://www.w3.org/Provider/Style/URI)
> 
> ```
> - dan
> 
> ```
> 
> –  
> Dan K. [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://www.dankohn.com/](http://www.dankohn.com/)tel:+1-415-233-1000
