Put Your Controllers on a Diet already! 3
If you’re working with Ruby on Rails and are looking for ways to improve your existing code base, I would encourage you all to read the following blog posts.
- Skinny Controller, Fat Model, Jamis Buck
- Find methods in controllers, by Graeme Nelson
- RailsConf Recap: Skinny Controllers, The Rails Way
- Rspec notes from the trenches 2, by Courtenay
Hopefully… you’ve already read each of them and as a result… put your controllers on a diet.
Enjoying the content? Be sure to subscribe to my RSS feed.





Are there performance increases in having smaller controllers? I understand that moving a a find method out of the controller into the model may look nicer, but it seems to me that it is an extra step. Why is doing it this way better? Thanks.
Dan,
In general, you’re not likely to find the application speed change much if the code is in the controller or the method. What is being advocated is a cleaner way of developing MVC applications. If we start looking at our Models as a set of APIs that interact with our data source, we can call upon their services and get what they provide us. We provide them with some parameters and they return it. By reducing the amount of code in our controllers, we’re also able to test the behaviour of our models much more efficiently. The more business logic that you can keep in your models.. the better. Perhaps there needs to be more discussion about what is and isn’t business logic.
That explanation makes perfect sense. As someone new to Rails I found myself using models to declare relationships and do validation but not much else. I think many people like myself would find articles about business logic very useful. Thanks.