Renaming RHTML to ERB
March 4th, 2007
As you may have read in The Latest in Rails, .rhtml is deprecated and will be gone in Rails 3. Brandon put together a couple lines of ruby which performs an svn mv on each of your rhtml view files. I wrapped it in a rake rask, threw it in my Rakefile, ran it, removed it from my rakefile and my job was done. For your enjoyment, here it is:
namespace 'views' do
desc 'Renames all your rhtml views to erb'
task 'rename' do
Dir.glob('app/views/**/*.rhtml').each do |file|
puts `svn mv #{file} #{file.gsub(/\.rhtml$/, '.erb')}`
end
end
end
You can grab the code from pastie.
Note: If you aren’t using rails revision 6178 or newer of edge rails, don’t do this.
Update: Josh pointed out in the comments below that it should actually be .html.erb instead of just .erb. Here is a pastie to do this instead.
8 Responses to “Renaming RHTML to ERB”
Sorry, comments are closed for this article to ease the burden of pruning spam. If you have any further comments, just send me an email.

March 5th, 2007 at 01:17 PM
The rake worked great, thanks. I’m on revision 6339 of 1-2-stable, and getting “Template Missing” and “No Template Errors”. Any advice?
March 5th, 2007 at 01:27 PM
FYI, that needs to be revision 6178 of true edge rails. 1-2-stable doesn’t include this as of 3/5/7.
March 5th, 2007 at 07:32 PM
Very useful. It’s going to take a while to get used to the new extensions but they are definately the way forward.
March 5th, 2007 at 07:46 PM
@Nathan – I have updated the article to mention edge rails. I assumed it, but should have put it in the post.
March 5th, 2007 at 08:49 PM
As I mentioned in a comment on Brandon’s blog, it should probably map .rhtml to .html.erb, not just .erb. The plain .erb extension will work, but .html.erb lets your favorite editor do syntax highlighting, and will also get to do some magic with automatically figuring out MIME types for the response. The generic form is .[format].[processor] – so you could have .html.erb, .xml.builder, .xml.erb, .css.erb, etc. I’ll see if I can get the docs updated with this information.
March 6th, 2007 at 11:27 AM
@josh – I added an update to the article with a link to the new pastie that should do this. Thanks for the comment.
May 18th, 2007 at 06:05 PM
I recently had a few issues with RJS on the latest edge and have extended this code here to take care of rjs and rxml.
December 26th, 2007 at 10:01 PM
In http://pastie.caboo.se/45061.txt you probably want to go the .rxml to .xml.builder route rather than .xm.erb. The default 1.2 rxml stuff all used builder rather than erb, I believe.
Cheers, Walter