Renaming .rhtml to .erb using Ruby

rails | ruby | subversion March 04 2007

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
posted by brandon
comments feed

7 comments

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

    Dr Nic Dr Nic
    March 04, 2007 at 03:03 AM
  2. I think that should map .rhtml to .html.erb, not just .erb on its own.

    josh josh
    March 04, 2007 at 11:46 PM
  3. 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?

    Jamie Hill Jamie Hill
    March 05, 2007 at 07:37 PM
  4. 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.

    Chris Chris
    March 05, 2007 at 09:26 PM
  5. 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'.

    Brandon Brandon
    March 05, 2007 at 11:06 PM
  6. 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.

    josh josh
    March 06, 2007 at 02:08 AM
  7. seems as if show.html.erb already works, but what about partials like _foo.html.erb? still needs :partial => ‘foo.html’

    Christoph Christoph
    April 11, 2007 at 04:17 PM

Speak your mind:

(Required)

(Required)


(You may use textile in your comments.)

About

I'm Brandon Keepers, a web application developer that likes beautiful code, valid markup and adherence to standards. As a part of Collective Idea in Holland, Michigan, I practice Agile software development primarily using Ruby on Rails.

-86.103171 42.785037

Contact:

more ยป

Syndicate