Read my latest article: Was away on vacation (posted Sun, 11 May 2008 22:33:00 GMT)

Put Your Controllers on a Diet already! 3

Posted by Robby Russell Tue, 19 Jun 2007 13:16:00 GMT

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.

Hopefully… you’ve already read each of them and as a result… put your controllers on a diet.

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
Comments

Leave a response

  1. Avatar
    Dan Wed, 20 Jun 2007 04:24:14 GMT

    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.

  2. Avatar
    Robby Russell Wed, 20 Jun 2007 05:45:12 GMT

    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.

  3. Avatar
    Dan Wed, 20 Jun 2007 14:01:26 GMT

    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.

Share your thoughts... (really...I want to hear them)

Comments