undefined method `relation’ for nil:NilClass on Heroku

I host almost 100% of my open source projects on Heroku, it’s amazing how easy it is to setup and how “out-of-your-way” they are. Today, while working on one of my open source project I encountered this error: View the code on Gist. It was right after I deployed and migrated the database. After about 5 minutes of head scratching I came across an answer on stackoverflow saying you have to restart your app after a migration for it to pick up on schema changes.

The simplest Enum you will ever find for your ActiveRecord models

I have been using a really useful snippet for a while now. While dropping it today into a project I realized just how powerful it is: it’s a drop-in and will work on any project it’s database agnostic it’s dead simple it’s not sensitive to enum changes and more and more Just as an into, an enum is a way to have string represented as integers in your database.

Showing the git commit SHA that is currently deployed

I cannot count how many times I (or others) have asked the following question: What is the difference between master and the production version? We deploy about 3-5 times a day and we merge code about twice as much into master (some days, even more then that). We deploy to servers with Capistrano, Capistrano has a very useful feature to write a REVISION file to the root of the project, this file contains a single line with the commit sha.

10 Things You Didn’t Know Rails Could do

James Eduard Grey published a presentation of a talk he did in RailsConf. It is pure gold, so many tips and tricks, I promise you, some of these will be new even to the most experienced of Rails developers. 10 Things You Didn’t Know Rails Could do // Speaker Deck.

Pivotal Tracker Git integration with ease

This post makes 2 assumptions You are working with Git You are working with Pivotal Tracker At Gogobot, we work with Pivotal Tracker (for various reasons). Pivotal Tracker has very good Git integration, when you commit (and push), the commits can show up as comments to the story. Another very good thing is that you can change the status of a story just by a commit, you can finish, deliver or anything else you might want.

Decorating Devise’s current_user with Draper – Ariejan.net

A great trick to decorate the current_user method from devise using Draper. IMHO it’s actually applicable to any authentication system out there that is using current_user but that requires some testing. Decorators are an awesome way to remove logic from the view or the models, so the models have real business logic and the rest can be “decorated” with another class. If you are looking for more information about decorators, Ryan Bates has a great screencast about it here: http://railscasts.

A Baseline for Front-End Developers – Adventures in JavaScript Development

I stumbled upon this terrific post on Twitter. This post goes into details (very deeply) about what it takes to be a Front End developer these days. The amount of things and tools you need to know are overwhelming. I recommend taking the time and reading it, it’s long, but worth every second you put into it. A Baseline for Front-End Developers – Adventures in JavaScript Development.

Find the source location of a method in your project

Ruby/Rails project sometimes make it hard to find the source location of a method. Sometimes, Duck typing, meta-programming and just plain bad design make it really hard to find where a method was defined and how. Luckily, there’s an easy way around this. So, here’s an example. A few moments ago, I came across this line: First thing I did (obviously) was going to the user class and searching for this method.

Testing the Notifier class with Rspec

Today, I needed to spec the Notifier (mailer) class in a Rails project. I don’t mean to spec the view, I just needed to test if the Notifier class method was being called with some params. For example, I had this user story As a User When I am an owner of an issue And the issue status changes I want to get an email So, all I had to to in my spec, is to test if the Notifier class was being called, I am testing the view in the notifier_spec, so no need to test it twice.

Run your specs in logical groups

I stumbled upon this StackOverflow question: testing – Organizing rspec 2 tests into ‘unit’ and ‘integration’ categories in rails – Stack Overflow. Basically, the guy asks how he can run specs isolated into logical groups, running the unit without running the integration and so on. At Gogobot, we have exactly that, since we run our specs in the CI, we can decide which to run, and they run one after the other and dependent on each other, so if you fail UNIT, the build fails, no need to continue on.