Ruby on Rails Saturday, July 3, 2010

On Sat, Jul 3, 2010 at 3:30 AM, bingo bob <lists@ruby-forum.com> wrote:
>
> Thanks to all, settled on this code in the end in case useful to anyone
> else - further tips appreciated

>    banner = BannerAdvert.first(:conditions => [ "published >= ?", 1],
> :order => "RAND()")

Even if you're currently only working with a single database, it might
be a good idea to abstract that last statement. Different DBs use a
different syntax, so for example I'd write that as

:order => RANDOM

where RANDOM is set in an initializer based on the DB actually being
used, e.g. <http://pastie.org/1029327>

I work in a lot of "mixed" environments, so that may be more useful to
me than most people, but...

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment