opensoul.org

Renaming .rhtml to .erb using Ruby

Even though Rails isn’t dropping support for .rhtml in favor of .erb for a while, it doesn’t hurt to switch now (if you’re using edge Rails).

After a brief, thoughtless, moment of typing svn mv file.rhtml file.erb a couple of times, it donned on me that I’m not a monkey.

Dir.glob('app/views/**/*.rhtml').each do |file|
  puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.erb')}`
end

rails, ruby, and subversion March 04, 2007

7 Comments

  1. Dr Nic Dr Nic March 4, 2007

    To save other monkey men, I’ve added it to the snippets site

  2. josh josh March 4, 2007

    I think that should map .rhtml to .html.erb, not just .erb on its own.

  3. Jamie Hill Jamie Hill March 5, 2007

    josh: I’d not thought of using .html.erb, I suppose it help with distinguishing their content e.g. .mail.erb for mail templates.

    Maybe there should be some kind of convention for these?

  4. Chris Chris March 5, 2007

    I agree … I understand the move to a more general file extension but I’d prefer to have it be as self-explanatory as possible. I throw in my vote for something like .html.erb and .mail.erb.

  5. Brandon Brandon March 5, 2007

    I didn’t like the idea of .html.erb at first, but it’s growing on me. But, if I’m not mistaken, without a patch to core, controllers would look really ugly because you have to explicitly state the views to render (:action => 'show.html'.

  6. josh josh March 6, 2007

    Brandon, the show.html.erb style of naming will be supported in core. I had assumed that’s how it was already, but I jumped the gun. However that will be how it works shortly. show.erb will work, and so will show.html.erb. Putting html in the filename will automagically set the mime type on the response, and it also lets TextMate (or whatever) format syntax.

  7. Christoph Christoph April 11, 2007

    seems as if show.html.erb already works, but what about partials like _foo.html.erb?
    still needs :partial => ‘foo.html’

Post a Comment

Comments use textile. Anonymous comments will be deleted.

My name is Brandon Keepers. I like to build things, usually in Ruby or JavaScript. I work at GitHub and live in Holland, MI.

Popular Posts