Next Post
Previous Post
strings of my
incoherence
I'm Tal Atlas.I'm currently working at OMGPOP and built Pictureclub. I got my ME and BS at Colorado School of Mines. I'm a ruby programmer and general web developer. This is a collection of random things I find intresting from across the web.
named_scope find options

strelau:

Let’s say you have


named_scope :red, :conditions => {:color => 'red'}

Do not do this:


Shirt.red(:limit => 1) #=> ALL red shirts

You will get all red shirts. I don’t care how many you limit to, you will get them all. Instead, you need to chain using find(:all) or it’s alias all:


Shirt.red.all(:limit => 1) #=> ONE red shirt

This has been your Rails public service announcement for 17 September 2008.

Wouldn’t it be easier to do this:?


Shirt.red.first/last
Ruby Rails Tags
blog comments powered by Disqus