Skip to content


Some Common Tricks with Ruby on Rails

Today we will use Ruby on Rails along with some Javascript libraries to code a few common patterns –

  • Autocomplete in a text box
  • Uploading files by dragging and dropping them into an area inside a browser.


The Javascript library, jQuery.token-input, is great for quickly building a Javascript-based autocomplete solution. You have to do only three things to get started:

Read More →

LAMP Adventure: Phusion Passenger From Soup to Nuts on Ubuntu

I am conducting a workshop on how to deploy Ruby on Rails apps on a (Ubuntu) virtual private computer (VPC.) We’ll be using AWS Free Tier instances (t1.micro) to do this. When you have a freshly initialized AWS Ubuntu instance, you have to install more than just the Apache server basics to get through the full installation. This post lists all the necessary steps.

Read More →

Silent Failures With Resque::Mailer

I was using Resque::Mailer, and couldn’t get it to work. I had what I thought was the simplest possible configuration –  in my mailer – app/mailers/user_mailer.rb – I had this:

class UserMailer < ActionMailer::Base
  include Resque::Mailer

  def alert_developers(u)
    mail(:to => "#{} <#{}>", :subject => "Hello").deliver

But I was getting nothing – no new queue being created in Redis, and certainly no mails being sent.

It wasn’t until I removed the Resque::Mailer that I realized what was going on. The Mailer was in fact failing because no SMTP from field had been set, but that error is eaten up by Resque::Mailer. When you are not using Resque::Mailer, the error shows up in the resque-web application and it’s easier to debug.

When I put in a default From field in my config/application.rb file, everything worked great:

config.action_mailer.default_options = {from: ""}

Now you know!

Ruby on Rails Testing: Some Basic Tips

At some point after you’ve started building your first Rails application, you are going to ask yourself, does this application work the way it’s intended to? If you aren’t asking this question, it means you aren’t a good enough application developer. No application can be built to be perfect, and the only way to get there is to make sure your tests are good enough.

The Rails framework has a lot of tools to help you build a comprehensive, and easy to undestand, set of tests. Surprisingly though, the testing framework in Rails is not nearly as intuitive as the basic development framework, so here are a few tips to get you started.

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 →

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.

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!