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
7 comments
To save other monkey men, I’ve added it to the snippets site
I think that should map .rhtml to .html.erb, not just .erb on its own.
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?
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.
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, 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.
seems as if show.html.erb already works, but what about partials like _foo.html.erb? still needs :partial => ‘foo.html’
Speak your mind: