The Rails Way

Posted by Colin A. Bartlett Mon, 21 May 2007 15:01:00 GMT

Sunday’s morning keynote at RailsConf was by Jamis Buck and Michael Koziarrski, both committers to the Rails core. The format was quite useful: a series of short code reviews from a variety of submitters to their website, The Rails Way.

  1. Jamis asked for a show of hands for who had read his “Skinny Controller / Fat Model” article. I, ashamedly, have not, but I intend to. I’ve heard the “fat model” concept more and have been trying to emphasize putting as much as makes sense into the Model, and less into the controller.
  1. They mentioned how you can override the #to_param method on an ActiveRecorded descendant in order to control what is used as the “id” string when building a URL in Rails. This would work perfectly with the pretty URLs I have been trying to use more and more.
  1. Jamis stresses how we should all strive to make our code “intention revealing”. One of the beauties of Ruby is the flexibility and expressiveness it allows you. Wherever possible, we should structure our code to be readable and even self-documenting. And where our code does not clearly reveal our intentions, we should document liberally with comments.
  1. #with_options seems to be a pretty slick little method that I have to try. It’s a method on Object that allows you to prevent repeating the same options on a series of method calls.
  1. Many people forget to actually use the ActiveRecord associations they setup. For instance, instead of People.find(:all, :conditions => [“company_id = ?”, 99]) one can do something like @company.people which can make your code much more readable and DRYer, too.
  1. And finally, they showed a code example that used the #returning method wrapped around several lines of code in a method that was to return something. Even after an explanation, I didn’t quite get how this worked. So that’s something to investigate.
Comments

Leave a response

Comments