What's New in Edge Rails: .rhtml and .rxml to Die a Slow and Painful Death

Posted by ryan
at 9:52 PM on Tuesday, February 20, 2007

In a bout of semantic house cleaning it’s been revealed that the .rhtml and .rxml file extensions will be deprecated in favor of .erb and .builder, respectively.

Why such a change – well, .rhtml files are not strictly html files. They are generic embedded ruby files that can be used for email templates, csv files, vcards etc… .erb is just a more generic, accurate extension for the file type. The same goes for .rxml – it can be used for more than just xml files. Think of all the rss feeds you’ve written with rxml files. Now you can stop being tied down by the limited .rxml file extension and can start using .builder.

Don’t worry about your existing app breaking though, the ‘old’ extensions won’t be fully deprecated until Rails 3.0. ... whenever that might be.

tags: rubyonrails, rails


Leave a response

  1. dylanFebruary 20, 2007 @ 10:10 PM

    nice… makes sense !

  2. maxFebruary 21, 2007 @ 12:46 PM

    Oh that’s some nice info. And I can agree this really makes sense.

  3. Thomas AylottFebruary 23, 2007 @ 08:42 AM

    What if you have html, javascript, css and other stuff being dynamically generated, all with file extensions of .erb?

    Using the same file extension for multiple kinds of documents can cause a bit off annoyance when switching between them in TextMate. Since you have to manually tell the app to switch language parsers.

    I use the TabMate plugin to make TextMate support modelines. (http://konstochvanligasaker.se/tabmate/) But that’s really not ideal.

    What about patching Rails to support .erb.* ? That would allow you to do stuff like: .erb.html .erb.css .erb.js etc… And that’d be neat.

  4. Ryan DaigleFebruary 23, 2007 @ 09:04 AM

    Thomas: I hear you – but the switch from .rhtml to .erb doesn’t really change this, so this was an issue prior to this fix as well, yeah?

  5. David DemareeMarch 02, 2007 @ 01:03 PM

    Thomas: You can always open up the Bundle Editor in TextMate to add the new extensions, like so:

    1. Select Bundles > Bundle Editor > Edit Languages… from the menu bar. 2. Find and un-collapse the Rails bundle in the left-hand list. 3. Select the ‘Ruby on Rails’ item. In the code editor at left, the second line should say `fileTypes = (‘rxml’);` Just change this to `fileTypes = ( ‘rxml’, ‘builder’);`. 4. Select the ‘HTML (Rails)’ item. Here we’re doing pretty much the same thing—change that second line to `fileTypes = (‘rhtml’,’erb’)`. 5. Close the Bundle Editor window. You’re done.

    From then on, any .erb or .builder files you open will be treated like the .rhtml and .rxml files they’re replacing.

    That being said, I would kind of like to see some support in Rails for ”.html.erb” or ”.css.erb” extensions. Even if Rails treats them identically to plain old .erb/.rhtml, it would be useful in TextMate because one could have the syntax highlighting and editing shortcuts for that particular language (like CSS), as well as highlighting and shortcuts for ERb. I think it’s great that the default extension is more semantically accurate, but I’d love some way to distinguish between different kinds of .erb views. It would be like how ActionMailer distinguishes between parts of a multipart e-mail template using .type.rhtml.

  6. Brian HutchisonMarch 06, 2007 @ 02:10 PM

    David, you are spot on. We absolutely need to be able to distinguish between different file types, even if Rails doesn’t care. I’d prefer a index.html.erb and index.wml.erb, etc.

    In fact, there may be nothing stopping us from doing so – why would or shoud Rails care if its index.html.erb or index_html.erb? Hopefully enough people try this on edge so we can find any problems ahead of time.

  7. necMay 10, 2007 @ 11:45 PM

    you textmate people. what has this to do with rails? just hack your editor.