Posts tagged as:


This is a basic demonstration of adding a rake task to Ruby on Rails. Some of the same principles apply to Rake in general. You also see how to call out to the command line and how to convert ERB and HTML to HAML.

Download 51.9 MB
Download (iPod & iPhone) 30.8 MB


What is HAML?

HAML is a markup language. It’s specifically designed to replace the HTML + ERB combination typically used in Ruby applications to render web pages.

Why I like HAML

HAML is nice for several reasons, all revolving around how its files are structured.

First, it’s indentation driven. I have run into a few issues with indentation, but for the most part, it’s pretty clear which parts of the page are within other parts of the page. I’ve never been a fan of whitespace delimited code, but in this case, it’s kind of nice.

Second, adding a class or id to an element on your page is as simple as #id or .class rather than class=”class” or id=”id”. It’s not just about saving typing. I actually find it easier to read.

Third, HAML includes SASS. SASS, or syntactically awesome stylesheets, give you a lot of features like storing your colors, sizes, and other common settings in variables, nesting styles, and inheritance. This saves you a TON of copying and pasting in your stylesheets. You can say $chadfowlerpink instead of #993366. (Click here if you’re wondering about Chad Fowler pink.)

Finally, you don’t have to declare your div tags. This is particularly useful because most layout these days is done using div tags and css attached to your classes and ids. So, instead of <div class=”…”> all over the place, you see .class1.class2.class3#id.

Sounds Great! Why Wouldn’t I Use It?

HAML use really boils down to the people involved. I’ve worked with several designers who work very well in HTML and CSS. I’ve also worked with several developer who have never programmed with HAML. These are the two types of people you need to consider when choosing HAML. Collaborators and maintainers.

Is it worth forcing collaborators like designers to undergo the learning curve to learn to use HAML? HAML comes with an HTML converter. Is it worth the extra step if they’re not going to learn HAML? Weighing the collaborators’ learning curve against the increase in productivity you’re likely to see as a developer is worth considering.

As for maintainers, keep in mind that you’re not likely to be the programmer building this project forever. Are you making it more difficult for your employer or client to find someone who can pick up their application and continue to work on it? Are you adding to the training required for new employees? (I don’t find this to be too much of a problem with new developers.)

HAML doesn’t have a steep learning curve, so in most cases, using it is worth it. But these are questions to keep in mind.

Where do I get HAML?

You can find out more about HAML at To install it, just
gem install haml

{ 1 comment }

In this screencast we’ll cover using variables, mixins and operations with LESS while building the header for the our Flitter front end.

In this screencast we’ll cover using variables, mixins and operations with LESS while building the header for the Flitter front end.
Download 89.1
Download (iphone & ipod) 50.4


In this screencast we’ll cover the basics of setting up a LESS file to compile into CSS as we provide an HTML front end to Flitter, a Ruby on Rails Twitter clone.
Download 55.1 MB
Download (iphone & ipod) 30 MB


Serving static pages with Rails Metal is actually very simple. Here are the assumptions we’re making.

  • Each static page’s content is made up of valid HTML.
  • Each static page has a path and content stored in a StaticPage object as defined by the StaticPage model.
  • If the path browsed matches the path in a StaticPage object, the content is what is to be delivered.

Here’s the code: [click to continue…]


Have you ever wished you could mix Rack or Sinatra into your Ruby on Rails application just to get its raw throughput on certain parts of your application?

Let’s face it, sometimes, the Rails framework is overkill when we’re returning a simple string or an object in JSON as our response. Your answer for these instances is here. Rails Metal.


Some people have reported huge speed increases in Rails Metal over the Rails MVC framework. This article claimed a 25x increase over Rails. Pratik Naik from the Rails Core team benchmarked a more believable increase of 4x. Whatever the case, the performance advantage is worth noting.
[click to continue…]


When I started writing part II, I started writing about models. As I got a little further along, I realized that it would be more helpful to provide an overview of the controller, which provides the data that goes into your web page, before I showed you how to get the data out of the database. My hope is that you’ll read this thinking of how you want the data provided, which adds context to part III on models.

Controllers are Where the Work Gets Done

Have you ever worked with one of those people who knows exactly where to go to get everything he needs. Can delegate his tasks effortlessly, and then pull it all together in the end. That guy would be our controller. When your website’s user browses to the page, the Rails engine picks up the request and decides which controller to send it to. More specifically, it decides which method in the controller to send it to. The methods on the controller are referred to as actions.
[click to continue…]