Skip to content


Subclassing Models In Rails Is Called Single Table Inheritance

There’s one thing I’m beginning to not like about the Rails framework a little, and that’s the penchant that it has for making up names for concepts that already exist in programming languages.

If you have been programming in object-oriented frameworks for a while, you’d be surprised to know that Rails likes to call it “single table inheritance.” Why not just call it “class hierarchy” or maybe even “model hierarchy”?

Read More →

Ruby Metaclasses: What Are They Good For? Part I

I’ve been playing around with Ruby for a while now, and I know that you can create meta-classes, but why this is a feature designed into the programming language hasn’t been very clear to me. Until today, when I found a use-case that really brought it home to me.

A critical part of understanding the reasoning behind having meta-classes was actually when I took some time to understand what the @ and @@ notations really do. A lot of tutorials and descriptions will say that this is the syntax for defining, respectively, “instance variables” and “class variables.” This isn’t entirely true.

Read More →

Rails Adventure du Jour: Testing!

So I’ve started testing my code now, and delved a bit into the world of RSpec, Capybara and BDD.

This will take a while to figure out but here are two things I learned that aren’t really described anywhere in the most popular tutorials on Rails testing:

  1. All your spec files should end in _spec.rb
  2. It’s good to know what matchers and helpers to include – config.include Devise::TestHelpers, type: :controller inside the block of RSpec.config and require ‘cancan/matchers’ are two good ones to add, if you have authentication and authorization going on with your app.

Technical Adventure du Jour: Setting Up LAMP on Ubuntu From Scratch

So yesterday I decided that I was going to distract myself a bit by moving all my websites to a Digital Ocean “droplet” (virtual machine – why does everyone need to find a cute name for the same idea? Get off my lawn, you stupid kids!)

I’ve done a Ubuntu setup of the LAMP stack a few times now, but everytime I forget the little gotchas, so in case someone else out there is doing this, here are a few tips:

Read More →

Rails App With Goodies: Adding Devise, CanCan And More Automatically

I have been teaching myself Rails now and listening to many of Ryan Bates’ most excellent Rails Casts, about which I cannot say enough good things.

I figured there’s usually a small list of things that most web apps tend to need, and if you’re a beginner Rails programmer like myself, you have probably spent some time trying to learn how to put all this code in. In fact, if you have RailsCast religion like I do, you have been probably copy pasting it from Ryan’s tutorials, except now you need to build a new app that does some other cool thing and you can’t remember all the Devise, CanCan, DoorKeeper, OAuth magic you painstakingly put together the first time around.

And even if you know these gems inside-out like the logo of your favorite brand of yogurt, and can paste in their configurations with both hands cuffed, wouldn’t it be nice to have a simpler way to do it?

Well, now you do! Head on over to this Github repo and quickly get Devise, CanCan and OmniAuth (with two providers – Facebook and Twitter!) running in your app.*

Read More →

Rails(cast) Gotcha: Using Devise, Doorkeeper and OAuth2 defaults

Now with Rails4 updates! This post has been getting a lot of search engine love, so I’m working on making it as helpful as possible. Feel free to ask questions in the comments section!

I love Ryan Bates, and I love Railscasts! The Rails learning curve is significantly leveled down by these excellent tutorials, or at least it adds a very helpful set of railings to drag oneself up that hill by.

I’m trying to hook up Devise and Doorkeeper together to build an application that is going to expose its data via an API. If you, like me, are learning how to do this using Mr Bates’ excellent teachings, you will probably have listened to Railscast #209, and are in the middle of Railscast #353.

I thought I’d add some notes for future n00bs to consider, based on a few hiccups I had:

Read More →

Rails and Github: Some Gotchas

I am working on a Rails3 application, and learned some interesting gotchas today.


  1. It was good to be reminded that when you create associations, you don’t create the foreign keys automatically – you have to figure out how to make the corresponding changes to the database yourself.
  2. You can’t call a model asset. Turns out Rails(3) has already decided to use that word to describe where it puts stylesheets and JavaScript files, so calling /assets/1 gets Rails very confused – it first attempt to find a file called “1” in the assets directory.
  3. has_belong_to_many, aka “HABTM,” is “deprecated” in Rails3, in the sense that most people will probably start with a HABTM but use it for a complex model where they add additional attributes to decorate each element (edge) in the many-to-many graph. So for example if we assign categories to articles, we might additionally atach a timestamp to each category assignment, which would be a new attribute.

Git and Github

  1. Once you’ve made your first commit, all your files are essentially part of your versioning system. If you are going to remove a file, do so via the git rm command. Otherwise, you might your app behaving differently in your development and production environments.
  2. If you use the https URI for your Github repo (like,, you can’t use SSH keys. If you want to do that, you have to use the http version, like so:
  3. git remote set-url <your Github remote name>

I am sure I’ll learn more as I go along!


Heroku and Public Keys: The Full Monty

When you first install the Heroku Toolbelt on your machine, there’s a good chance you will run into a problem with pushing your code via git to the Heroku remote. The common issue is an error message that looks something like this:

Permission denied (publickey).
fatal: Could not read from remote repository.

What you are seeing here is a problem with how your private/public key pairs are configured between your computer and the Heroku server. If you already know what public/private key pairs are, you can skip ahead to the explanation of how to fix this.

Read More →