Rails: Queriyng entries with conditions

M

Malte Harder

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
 
D

Dema

Malte said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,167
Messages
2,570,910
Members
47,453
Latest member
MadelinePh

Latest Threads

Top