Skip Navigation

Ruby on Rails Cheat Sheet

The Ruby On Rails cheat sheet is designed to be printed on an A4 sheet of paper and live by a developers desk, to make life a bit easier. A description of what is on the cheat sheet follows, or if you are impatient, you can go straight to the full size Ruby On Rails cheat sheet.

I am no expert in Ruby, On Rails or off, so to ensure this cheat sheet was as useful as possible, I pestered the very helpful Amy Hoy of (24)Slash7 and David Heinemeier Hansson of Loud Thinking into giving me a hand. Thanks, both of you - I appreciate it. In the same vein, though the cheat sheet has been checked there is a chance there is the occasional typo - if anybody spots a mistake (or something that could be worded better) please let me know.

Default Directory Structure

Thumbnail highlighting default directory structure. Ruby on Rails by default uses a rather large selection of folders and files, organised into a directory structure. This is a great feature, but does occasionally lead to people getting slightly lost and forgetting where to find something, especially if what they are looking for is something they use infrequently. This section shows visually the default directory structure of a Ruby on Rails site.

Pre-Defined Variables

Thumbnail highlighting pre-defined variables list. Ruby on Rails, like most languages, includes a large number of predefined variables. These shorthand variable names are often tricky to dig out from the back of the mind when actually needed, so here is a convenient list of the most useful of them.

Reserved Words

Thumbnail highlighting reserved words. In much the same way as Pre-defined variables, Ruby on Rails makes use of reserved words and these are also often not easy to remember. Using them out of context can cause all sorts of problems, so this list is provided to ensure that doesn't happen. Ignore it at your peril!

Regular Expression Syntax

Thumbnail highlighting regular expression syntax. It seems that no matter the language, most developers always spend some time stumbling through regular expressions before they are comfortable with them. Ruby on Rails is no different, and the regular expression syntax is the same familiar syntax as used in PHP and Perl. This section outlines the building blocks of patterns in regular expressions for Ruby on Rails.

Methods

Thumbnail highlighting methods section. Ruby on Rails is very much an object oriented language. Every object has methods. These sections list the useful methods for working with String, Array, Time and Regex objects. It also lists validation methods and methods from the enumerables mixin - which are some of the most looked-up.

Download

So now that you know what it does, please feel free to print out the Ruby on Rails cheat sheet:

And finally, if you like the cheat sheets, and want to say thanks, please consider buying me something from my Amazon Wishlist. Thankyou very much to those who have already hunted it down and sent me something nice - I'm very grateful!

Please note: If you wish to link to the Ruby on Rails cheat sheet from elsewhere, please link to this page so others find the description, rather than linking directly to the sheet.

66 comments

Bookmarked!As all the other cheatsheets! ;)
we are only waiting for a LaTex cheat sheet at that's all folk!
 United Kingdom #3: January 11, 2006
I love you cheet sheets, and when I win the lottery I will buy you that cammera on your wishlist
Nice! Man, you're the cheat sheet maestro.
I have three of your other cheat sheets on my wall behind my monitor. This is the best one yet - you rock!
Ale Bairos
Brazil #6: January 14, 2006
Nice work. The ideal is to bind it to RoR release process in order to automatically generate it.
I was inspired by Amy Hoy as well and created a cheatsheet (cheat mini-book? 14pages) and it's getting a lot of link-love from del.icio.us, etc.

http://www.blainekendall.com/index.php/rubyonrailscheatsheet/
JesusHatesYou
Germany #8: January 22, 2006
How about a HTML Cheatsheet? There's some meta tags and things like that I always forget, or some simpler markup I just all too seldom use.

Oh and I might have found a "bug" on your site. Whenever I press tab (I use my keyboard a lot, who needs a mouse, right) the site scrolls to the top, but the selection is set in the correct order. I can only imagine it being some faulty JS.
I use Opera 8.51 and did not test this error in inferior browsers (=all others).
In your Regular Expression Syntax section, you refer to "[abc]" as a "range". This is a character set and can /contain/ a range with the a-z syntax. Perhaps you'd like to change to something like: "[a-cg]" => A character from the set a, b, c, or g

Much of your "Rails" items are just "Ruby" items. Perhaps having a <gasp/> two-page cheat-sheet where one side is Ruby and the other is Rails? You could include sections on ActiveRecord, ActionPack, ActiveSupport, etc. I was thinking that sections on redirect_to, request.get?, text_field, and the like would be a tremendous addition.

-Rob
I'll second Rob's suggestion above: since Ruby and Rails are really two very distinct entities, it'd be a great help to have a cheatsheet for each one. The current one is really more of a Ruby cheatsheet -- one that I think most people will find helpful -- but I'd love one that had more Rails-specific stuff.
I'll third Rob's comments - a focused Rails sheet would be great. Maybe even a simple one going over all the AJAX helper functions in some detail...this would probably be quite popular.
Perfect cheat sheets, very helpfull. Keep going on with next ones.
Alex MacCaw
United Kingdom #13: February 9, 2006
Just wondering when the pdf is coming out?
Jon
United States #14: February 16, 2006
I'll second the Ruby/Rails seperation thing.

Is there some way you can post the raw photoshop files (or whatever you used to create this)? I'd be willing to work on improving the cheatsheet and dividing it up, but modifying the raw PNG is a mess. If these things were easily modifyable we could keep them up to date to, with the new Rails 1.1 stuff.

Another useful thing for the sheet -- naming conventions, something like this would be great:

SomeClass
SomeModule
SOME_CONSTANT
$SOME_GLOBAL
some_variable
some_method
@some_instance_variable
SomeClass.some_method
Kevin
United States #15: February 16, 2006
Saw this bit on a http://discuss.joelonsoftware.com/default.asp?joel.3.309321.45

This would be also be a good addition to the cheatsheet:

Rails needs to put a set of simple rules in a place where most newbs will see it. Things like:

-name your tables in the plural
-foreign keys should always be named like so: tableNameInSingularForm_id
So: user_id (foreign key) -> users (table)
-models are named singular
-controllers are plural, at least in some cases
-many-to-many jump tables should be named: alphabeticallyFirstTablePlural_alphabeticallySecondTablePlural
So: axes_users
-columns in many-to-many jump tables should be named like other foreign keys
So: axe_id and user_id
-columns named created_on and updated_on will automatically be populated correctly
Here is pdf version of this cheatsheed, I hope some one find it useful.

http://www.lacoctelera.com/myfiles/sitiolejano/ruby_on_rails_cheat_sheet.pdf
ryan
United States #17: March 28, 2006
not sure where to put this, but a useful cheat sheet may be for the "tiny but strong" templating class. its a great class, and having a reference sheet would make it even better, you can find the class at http://tinybutstrong.com/

just a suggestion.
Great stuff! I've printed this (and a few others) out and I'm sure they will come in handy down the road. Looking forward to more in the future - linux commands, vi, regular expressions? Thanks again!
ylon
United States #19: April 29, 2006
Yes a Ruby and then a Rails cheatsheet would be excellent in terms of helping keep things straight.
Cool! Thank you for your time and effort and making this cheatsheet available. It certainly does simplify things and make it a bit easier to get my head around RoR.
Anonymous
Romania #21: May 9, 2006
Nice job :)
Still waiting for the real PDF version. Could you spend another 10 minutes in order to post it?!
Another vote for separate Ruby/Rails cheatsheets. Anyone who's serious about Rails needs to be serious about Ruby as well.

There's so much Rails specific functionality that I'd love to see at a glance. I would even scrap the directory structure just to fit more stuff in. All the ActiveRecord stuff, all the helpers, etc.
Thanks! I just printed it out on an 8.5x11" glossy photo paper and it looks GREAT!
So, I've ordered you another item off your wishlist -- would this be enough to inspire you to make us the PDF now? Please, pretty please, with sugar and all that? :D
 United Kingdom #25: June 25, 2006
Hi, very pretty :) I'd just like to re-iterate the separation between ruby and rails here. I've come via google to look for a rails cheat sheet, and most of this one is ruby stuff (which I am familiar with). Something listing the active record relationships, or the names of the views that can be overriden from the struts,etc. would be most useful.
I've added the Ruby on Rails PDF. Xara Xtreme (the new version of my graphics software of choice) now has nice PDF generation built-in. With any luck, that will mean that this PDF is of better quality than the previous ones.

Please let me know if there are problems with the PDF. I'll be regenerating the whole lot over the next couple of weeks and adding PDFs where they are missing.
Hi,

I found the cheat sheet useful to get started.

Thanks
Me ,too.The hardest thing is always to get started.I found the cheat sheet very valuable
Albert Kok
Netherlands #29: July 7, 2006
Your cheatsheet has been my desktop background for quite some time now, and I actually use it. Great work!

Albert Kok
The Netherlands
Very useful cheatsheet, thanks alot !
I really appriciate your work.
Thanks
Andriy.Tyurnikov
Ukraine #32: October 27, 2006
It is hot =) do not stop! =)
Man, I just wanted to tell you how much I use your cheatsheets. I've got them printed in A5 (Classic planner size) and put behind a special tab in my planner. I have the RoR, PHP, MySQL, HTML Chars, CSS, JS, ASP and mod_rewrite sheets and just downloaded the reg expressions and microformats. These things are great for when I don't have my library of reference books (like at home on the weekend) and have saved me from 20+ minutes of searching online docs countless times.

I know you probably have tons of suggestions for new cheat sheets, but I thought I'd throw a few out there as well.

* Apache
* Perl
* Bash scripting
* Common .htaccess snippets
Hi Brandon,

Glad you like the cheat sheets, and find them useful. Thanks for the suggestions - I've got a few new ones on the way, and will add those to the list to do :)
Font broken on Adobe Reader for Linux
United States #35: December 19, 2006
Has anyone gotten this cheat sheet to render the fonts on Linux?
Stuart Coyle
Australia #36: December 25, 2006
This printed fine using xpdf on Linux.
Anonymous
United Kingdom #38: January 15, 2007
It's good!
And here's a new Rails website you may be interested in:
www.ChangingThePresent.org
omid
Islamic Republic Of Iran #40: February 6, 2007
Ruby iss best.
better than java.
only Rubyyyyyyyyyy.
Very nice cheats!

What about updating Rail's Cheat Sheet? Ruby on Rails 1.2.1 is out there :)
Great site, and awesome Cheat Sheets.

I;m with Julio, how about updating it for Rails 1.2.1?
Edmund
United States #43: February 22, 2007
Thanks for taking the time to share (for free) some concise info on RoR, that dude Dr. Lance is an ass hole.
Also, I love the name of the web-site... Respek!
yo, providing the directory-structure in your cheat-sheet is so helpful, need it daily
Superb cheatsheet, though I'd like to stick it on my wall in A3 format, so I wouldn't have to stand up, step there and stare at it but look at it from my chair and be able to read it. That is, I'd like you to make an A3 size pdf/png, since if I scale these A4 ones to 200% they lose image quality, and when printed it gets even worse. Thanks in advance.
Regards, cruox.
sean
Japan #46: May 18, 2007
Just a heads up: I didn't have the font you used (Verdana bold) on my computer, so the PDF came up gibberish. I'll just download the png instead. If you have the time, you may want to open the file in Acrobat, click on "Document properties" in the file menu, and make sure all the fonts are listed as "embedded subset."

Thanks for the hard work! Great sheets!
This is so cool. I am RoR fan, see my RoR blog:
http://www.rubyonrailsexamples.com/
Very nice stuff. My company is actually looking for Ruby developers if anyone is interested. Please email me for details!
Great! Thank you a lot for putting it together.
Awesome, awesome, awesome. Thank you.
Missing
United States #51: September 6, 2007
It's missing a lot of stuff
link_to ?
form_for ?
text_field ?
This is a great cheet sheet. I am was looking for some short tuts on rails and found your link on a blog. Could you create some with short examples. That would be great to use as a back up?
murphy
Germany #53: October 10, 2007
^and $ are the beginning and end of the LINE, not the STRING. Please correct this, as it typically leads to security issues.
Perfect for the newbie like me. Thanks for taking the time to put this together.
HECTOR RIOS
Unknown #55: November 1, 2007
Nice work. Thank you!
Dan Webb
United Kingdom #56: December 7, 2007
Brilliant cheat sheet. It's now stuck to my wall along with the CSS sheet.

I've just noticed the reserved word "thread" isn't on there.
Not cheating at all - just a big help!
John
Australia #58: January 21, 2008
Can't wait for update to Rails2.0, it's amazing and helpful.
thanks! very useful for me :)
Aren't ^ and $ for the start and end of the line, and \A and \Z for beginning and end? That could be a validation flaw!
Aren't ^ and $ for the start and end of the line, and \A and \Z for beginning and end? That could be a validation flaw!
Evan Anderson
United States #62: June 1, 2008
Awesome! Bookmarked your site for later browsing/discovery
Desert Fox
Myanmar #63: June 16, 2008
I great thanks all of your effort.
Many Cheat Sheet are very useful to Me.

Thanks Friend, Nice effort.
new version for Rails 2.1? So much has changed.
Bookmarked! This is great! =D

Post Your Comment

· Comments with keywords instead of a name have their URLs removed.
· Your email address will not be displayed or shared.

Live Comment Preview

 United States #67: 1 minute ago