Dr Nic

RadRails Templates Cheat Sheets

Now that RadRails is blessed with 100s of templates/snippets the challenge is now knowing what is available. Several people have had a crack at this: XSL conversions of the template XML into HTML, and Ruby scripts to convert the XML into text.

The nicest, most completest solution (that is, it is awesome and yet I didn’t have to do anything) is by Aran Donohue.

Cheat Sheets

Rapid Updates

Aran now wields a rake field to update these two wiki sites whenever the templates/snippets change. Sweet cheating goodness.

Sneak a peek

Cop a glimpse at Aran’s cheating via Subversion:

Prayer to the God of Cheating


RadRails Templates on Trac

I have started to cleanup the Ruby and RHTML templates previously released. They are now stored on SVN so you can get latest versions. They now have a ticketing system for improvements. They now have a Wiki for everyone to help everyone.


RadRails Templates now has a home: http://radrailstemplates.com/

Kyle from the RadRails is busy making improvements to template support for the next release, and has promised that the new and improved templates will also be included in it. Bonza.

Cutting edge releases

You can get the latest edge releases of the templates via Subversion: http://radrailstemplates.com/svn/templates/trunk/

Juicy new improvements

I’ve cleaned up a bunch of the original templates, and started to add new ones that seem generally relevant to everyone: see the CHANGELOG.txt

Extensions and modularisation of templates

Currently the templates come in two big XML files: one for Ruby editor, and one for the RHTML editor. On the plus side, this makes importing new templates easy: you delete all the old templates and them import the new file, and go for a coffee.

On the negative side, this infers all new templates need to go into the same file and thus are imposed upon everyone. Instead there might be templates associated with rails plugins, that aren’t generic.

I don’t have a good plan for what to do about this yet. In the short term, submit any patches or new template files to trac and we’ll figure it all out in due course.

If you want to create patches of your own templates see below.

Similarly, if you add new templates locally and don’t want to share but don’t want to lose them each time you upgrade, my initial suggestion is to do the following:

  1. Checkout the templates from svn: svn co http://radrailstemplates.com/svn/templates/trunk/ radrailstemplates
  2. Do an initial export of your local templates that you want to keep into a separate XML file
  3. Delete all local templates
  4. Import the radrailstemplates/ruby-templates.xml file, if its the Ruby editor, else the rhtml-templates.xml file for the RHTML editor
  5. Import your personal, saved templates on top
  6. Export everything on top of the radrailstemplates/ruby-templates.xml file (if its the Ruby editor, etc). Now you have modified your local copy of the templates.
  7. Now create a patch of the differences using svn.
  8. Attach the patch to a trac ticket. A description of each template added would be very handy as its very difficult reading the xml patch.
  9. Alternately, keep the patch in a safe place for a rainy day. But if you don’t want to share your templates you will hopefully be able to continually do svn update on the template files and your templates should be kept for you (unless you get nasty conflicts)

Port 8669

FIXED You can happily ignore this section, or read Ry’s comment for solution.

My skills with apache are apparently lacking. Why does the raw port number keep appearing in the url?

Its hosted on TextDrive, and the .htaccess file in my /web/public folder is:

RewriteEngine On
RewriteRule ^trac_common/(.*) http://radrailstemplates.com:8669/trac_common/$1 [P]
RewriteRule ^trac/?(.*) http://radrailstemplates.com:8669/$1 [P]
RewriteRule ^radrailstemplates(.*) http://radrailstemplates.com:8669/radrailstemplates$1 [P]

How do I fix this?

Post-Halloween RadRails trick – all TextMate snippets available

Textmate Snippets to Radrails

HTML snippets
Ruby snippets

I tease myself with things I can’t have – like watching TextMate demo videos. One wonderful video shows a test-driven design demonstration by James Edward Gray II where he used Textmate snippets to generate the various assert statements. For example:

ase => assert_equal(expected, actual)
asn => assert_nil(instance)
asm => assert_match(/expected_pattern/, actual_string)

I’d been using Corban Brook’s templates but they didn’t include any assert or migration templates. And I wanted them without having to spend $3049 on TextMate [1]

This made me cranky

Solution 1: Learn Emacs. Setting up Emacs with all the modules you’ll need is a non-trival exercise. That is, put aside a day or so and don’t expect to be finished when time runs out. Plus, a version of GNU Emacs for Windows hasn’t been released since 2005. Not a lot of OSS love there.

Solution 2: Offer to build Textmate for Windows. I’m sure I read once that the Textmate author was open to porting of Textmate to Windows. That must be the past, because their website claims very strongly that there will never be a port:

countless requests for both a Windows and Linux port, but TextMate remains exclusive for the Mac, and that is how we like it!

That’s just lazy if you ask me.

Solution 3: Port Textmate’s snippet libraries (bundles) over to RadRails. Textmate has a more powerful syntax for its snippets than RadRails has for its templates (a limitation inherited from Eclipse), but SUCCESS! On the 31st of October – the day when Textmate was lauded around the blogosphere for its Halloween theme, I ported all their snippets into RadRails. OoooOOOOHHH spooooky.

You can now access the latest and greatest in templates/snippets for Radrails, for Ruby/Rails and RHTML (or click on the yellow boxes at the top).


  1. Download the two template XML files.
  2. Open RadRails
  3. Go to Windows > Preferences > Ruby > Editor > Templates, to see the list of included templates
  4. Click on any template, and press Ctrl-A to select them all.
  5. Click on Remove, to delete them all
  6. Click Import…, select the file ruby-rr-templates.xml
  7. Change to Rails > Editiors > RHTML Editor > RHTML Templates
  8. Remove all the current templates
  9. Click Import…, select the file rhtml-rr-templates.xml
  10. Press Ok to close the dialog and you’re done

Too difficult? The next release of RadRails will include these new templates.

How to use templates/snippets?

You can peruse a textmate-snippets-cheat-sheet, but really, spend 20 minutes looking through the template lists in RadRails. The name of the template is the text you type into the editor to activate the template.

So, the name of assert_equals is ase. So, type ase and press CTRL-SPACE, and a list of options pops up. Press return on the selected option.

Want to see all available assert_* templates? Type as and CTRL-SPACE and there they are. Nifty.


The RadRails guys are going to host these templates to allow anonymous access to make submitting patches relatively easy (if you know how to wield SVN). In future perhaps there will be a nice website for collaboratively sharing and downloading updates to templates.

Templates for JavaScript and CSS

I’ve put in a request for adding template support for JS and CSS as I have ported the JavaScript+CSS bundles as well. We just need a UI to import them into RadRails.

[1] TextMate is 39 euros = $49 at the moment. Plus $3000 for a new Mac.