Skinny Controller, Fat Model

Posted by Colin A. Bartlett Sat, 02 Jun 2007 01:07:00 GMT

One of my favorite talks from RailsConf was by the team behind The Rails Way. Now back from the road trip and settled in, they have updated their site with some more details about one of the ideas they pushed: Controllers should be simple, basic, and generally have a lot less code then most of us use now. Most of your logic should end up in the model.

There’s many reasons for this but the three I like the most:
  1. It forces you to write code that more easily reused. Limits your temptation to copy/paste from one controller action to another.
  2. Your templates can become more details. @order.total instead of @total (which would have to be mapped to something logic in the controller.)
  3. The code is more easily tested. You can programmatically access the results of the methods in your model without having to munge HTML output from a controller.

Their post has all the details and code samples.

Trackbacks

Use the following link to trackback from your own site:
http://blog.kineticweb.com/articles/trackback/36

Comments

Leave a response

Comments