Re: Order by date

Toby Boudreaux
Sun, 24 Jul 2005 15:56:33 -0000

The Phrasebook design pattern allows you to keep your SQL statements
in a (single, usually) location. Instead of ever having SQL hard-
coded in your model layer, you ask the phrasebook for the SQL by key.

You might do something like:

        :conditions => [Phrasebook.get("salable_items_order_by"),
Time.now],

Or

def self.salable_items
   find_by_sql(Phrasebook.get("salable_items"))
end



Keep in mind that Time.now won''t necessarily get the time on your
particular DB box or boxes. That could be bad...

def self.salable_items
   find(:all,
        :conditions => ["date_available <= ?", Time.now],
        :order      => "date_available desc")
end




On Jul 24, 2005, at 11:46 AM, Abdullah Jibaly wrote:

>>> def self.salable_items
>>>   find(:all,
>>>        :conditions => "date_available <= now()",
>>>        :order      => "date_available desc")
>>> end



_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org