March 04, 2007
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
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?
Mar 05, 2007
FYI, that needs to be revision 6178 of true edge rails. 1-2-stable doesn’t include this as of 3/5/7.
Mar 05, 2007
Very useful. It’s going to take a while to get used to the new extensions but they are definately the way forward.
Mar 05, 2007
@Nathan – I have updated the article to mention edge rails. I assumed it, but should have put it in the post.
Mar 05, 2007
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.
Mar 06, 2007
@josh – I added an update to the article with a link to the new pastie that should do this. Thanks for the comment.
May 18, 2007
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.
Dec 26, 2007
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.