Jon Leighton

Rails controllers and OOP

I have written a much better explanation, please read that instead: Explaining Focused Controller

Rails controllers violate the Single Responsibility Principle. Each “action” has a different responsibility and should be contained in a separate object. Controllers are also hard to unit test, so we end up using slow “functional tests”.

This realisation lead me to experiment with altering the conventions for controller code, and today I gave a talk on the topic at Railsberry called You Hate Your Codebase & It’s Your Fault.

I wrote a plugin named Focused Controller a while back, as part of this experiment, but have kept quiet about it until now, partly because it was undocumented.

But now I’m ready to announce it and I’m really keen for people to try it out and share their thoughts about this idea. I’ve gone into detail about the problems and solutions in the README, so I won’t repeat that here. Please just check it out!

20 April 2012