how to learn rails

Updated: September 12, 2013

A couple of people have been asking my where to start with Rails. I usually say it's easy! Just learn ruby then learn rails.

Well it's time to put my money where my mouth is. Here is a guide with some helpful resources on how to learn rails.

Step 0: Tools & Setup

Sublime Text

I love Sublime Text so much. It's pretty much an IDE once you customize it with plugins. If you really need an IDE you can try something like RubyMine. I've only used it a little and can't really speak it its usefulness.

Neither of these tools are free but you can use Sublime Text indefinitely if you're okay with a pop-up every now and again.

Install Ruby

If you're on a Mac then you already have ruby 1.8.x, so you can use that before installing anything. If you're on any other platform visit ruby's webpage. As of today, the two choices of ruby that you'll have will probably be 1.9.3 and 2.0.0. Go with 2.0.0.

I highly recommend that you use rvm or rbenv once you know what you're doing but, installing either one of these can be daunting task so it's okay to skip this step while you're testing the waters. Do not forget to do this at some point; I personally prefer rbenv.

Step 1: Ruby

You'll hear a lot of people say that you don't need to learn ruby to be able to work in Rails. This is false. Well, as a programmer I think it's better to learn the language and it's quirks before diving into a framework.

Try Ruby

Try ruby is a great place to start. The tutorial doesn't take long and is definitely worth doing.

Ruby Monk

Once you've tried ruby, head on over to Ruby monk and see if you actually picked up on anything.

Project Euler (Bonus)

If you want to truly tap into your ruby powers, a good place to do that is Project Euler. Register for an account and do a bunch of the problems using ruby.

Step 2: Rails

Rails for Zombies

This is a quick 'course' by the same people that made Try Ruby. It's a bit tricky, and you might be confused at some points, but it'll definitely give you an idea of what Rails is about. Do it.

Rails Tutorial by Michael Hartl

This is a great book and this is how I first go into rails. Also, the entire book is available for free!

Once you've read the book, you're good to go! You can now do Rails.

best terminal theme ever

Update : checkout Best terminal ever for a slightly more advanced but better terminal guide.

Best Terminal Theme Ever

Adapted from Noah Frederick's peppermint theme.

Step 1

Download the peppermint theme from the link above.

Step 2: Enable Terminal Coloring

Enable some terminal coloring by adding the following lines to your ~/.bashrc or ~/.bash_profile

COLOR_BOLD="\[\e[1m\]" COLOR_DEFAULT="\[\e[0m\]" PS1="$COLOR_BOLD\u@\h \w \$ $COLOR_DEFAULT"

Step 3: Git Coloring

Open up your terminal and paste the following line in:

git config --global --add color.ui true

And that's it, you're done. I didn't really like the default font for peppermint so I changed it back to menlo. Finally, I hit command+= twice to increase my font size and there you have it!

my interpretation of the factory pattern

I want to start off by saying that I’ve never really looked at the actual design pattern before writing

this piece. I’ve used a couple of factories in my days (unknowingly) but I’ve never really bothered looking into how they actually work, what they’re for or when to actually use one. Again, I wrote this before knowing the “official” factory pattern. This is just what I came up with, and I’m sure it’s been done before so please don’t troll me.

The Problem

So I started making a game, I figured I’ll write this game in Java using some basic SWT stuff and then port it to OpenGL using LWJGL. Cool. My game has stuff in it and I like making nice polymorphic hierarchies. Naturally my first solution was to make an abstract class and then to sub class all of my desired items. Something like this:

ReplaceableHorn < Item Brush < Item Food < Item

Well that works pretty well and this is how we’ve done it both our games. I started writing an abstract class called item, got that finished pretty quickly, made some instanced variables and some methods. Bam, done. Then I went on to make my first item, the “replaceable horn.” It was then I realized that the only differences between an abstract Item class and something that was extending Item were different values for the variables. I literally just needed these objects to have different values but behave in the exact same way. I didn’t actually need polymorphism.

The Solution: Make a Factory

As I’ve mentioned earlier, I’ve never actually used the factory pattern before but since first idea that popped into my head was, “Hmm I need some kinda item factory.” I figured I’d give it a shot.

The Factory

I made a class called ItemFactory which would have static function and variables and the information about the all of the item variables.

The Items

Next I made private nested class (within called ItemTemplate (I’ll probably end up changing it to something more meaningful). Making a private class adds some security so that if someone else were to use my code they would never make their own item; they would have to go through the factory.

The Interface

Using a private and nested class meant that I couldn’t really use this outside of No big deal, we just need an interface. This is where comes in. Item is an interface that has all of the methods I need from ItemTemplate. Now ItemTemplate will implement Item and bam we have a pretty robust design from a software engineering perspective.

Here’s the verbose version of what it looks like:

Public class ItemFactory {
    // Static stuff…
    // Variables
    public static Item createSpecificItem() {
        return createItem(ID_SPECIFIC_ITEM);
    private static Item createItem(int id) {
        return new ItemTemplate(id, STAT1[id], STAT2[id], STAT3[id]);
    // …
    private class ItemTemplate {
        // Variables
        Public ItemTemplate(int id, int stat1, int stat2, int stat3) {
        // …
        Public void method1 { // … }
        Public void method2 { // … }
        // …

Public interface Item {
    Public void method1();
    Public void method2();
    // ...

Cleaning up the Factory

I decided to make arrays for the different items that I wanted. This makes accessing them a lot easier and cleaner. I also avoid an if-tree by simply using an “id.”

守: Follow the rules.

破: Break the rules.

離: Make your own rules.