March 04, 2007

Posted by John

Tagged rake

Older: Helpful Railsmachine Scripts

Newer: How To Pimp Your Local Rails Setup

Renaming RHTML to ERB

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 Comments

  1. Nathan Colgate Nathan Colgate

    Mar 05, 2007

    The rake worked great, thanks. I’m on revision 6339 of 1-2-stable, and getting “Template Missing” and “No Template Errors”. Any advice?

  2. FYI, that needs to be revision 6178 of true edge rails. 1-2-stable doesn’t include this as of 3/5/7.

  3. Very useful. It’s going to take a while to get used to the new extensions but they are definately the way forward.

  4. @Nathan – I have updated the article to mention edge rails. I assumed it, but should have put it in the post.

  5. 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.

  6. @josh – I added an update to the article with a link to the new pastie that should do this. Thanks for the comment.

  7. 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.

  8. 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

Sorry, comments are closed for this article to ease the burden of pruning spam.

About

Authored by John Nunemaker (Noo-neh-maker), a programmer who has fallen deeply in love with Ruby. Learn More.

Projects

Flipper
Release your software more often with fewer problems.
Flip your features.