[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails: Queriyng entries with conditions

Malte Harder

2/10/2005 10:01:00 PM

Hi,

I'm writing a rails application where I query entries from a table which
have a date field. I want to have all entries after a specific date.
Rails maps everything very well, except if I use conditions:

Receipt.find_all ("date >= '2005-02-03'", "date ASC")

But I didn't find any method to convert a date to convert a time object
to a usable sql string.

Currently I'm using the following code:

class Time
def to_sql
return "#%.04i-%.02i-%.02i" % [self.year, self.month, self.day]
end
end

I think it's ok, but I don't want to use it if there's a rails helper
for something like this.

Malte


1 Answer

Dema

2/10/2005 10:22:00 PM

0

Malte Harder wrote:
>
> Receipt.find_all ("date >= '2005-02-03'", "date ASC")
>
> But I didn't find any method to convert a date to convert a time
object
> to a usable sql string.

You can try this:

Receipt.find_all [ "date >= ?", your_date ], "date ASC"

Rgds
Dema

Hint: You can get a quicker response if you use the Rails list or the
Rails irc channel for these kind of questions.